A Ruby implementation of the Myers diff algorithm.
Basically a minimal and incomplete port of the jsdiff Javascript library.
- Algorithm paper: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
- Reference JS implementation: https://github.com/kpdecker/jsdiff
You can use MyersDiff::CharDiff#diff(s1, s2)
to calculate an edit script that changes a string s1
into s2
.
The return value is an edit script, represented as an array of edit commands.
The edit commands are hashes that are formatted in three ways:
- Match:
{ count: <integer>, value: <string> }
- Add:
{ count: <integer>, added: true, value: <string> }
- Remove:
{ count: <integer>, removed: true, value: <string> }
diff = MyersDiff::CharDiff.new
diff.diff('abcabba', 'cbabac')
=> [{:count=>1, :added=>nil, :removed=>true, :value=>"a"}, {:count=>1, :added=>true, :removed=>nil, :value=>"c"}, {:count=>1, :value=>"b"}, {:count=>1, :added=>nil, :removed=>true, :value=>"c"}, {:count=>2, :value=>"ab"}, {:count=>1, :added=>nil, :removed=>true, :value=>"b"}, {:count=>1, :value=>"a"}, {:count=>1, :added=>true, :removed=>nil, :value=>"c"}]
- Update version file
- Run
bundle install
- Commit changes
- Add tag
git tag -s vVERSION
git push && git push --tags
gem build myers_diff.gemspec
gem push myers_diff-VERSION.gemspec