Skip to content

alextsui05/myers_diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Ruby implementation of the Myers diff algorithm.

Basically a minimal and incomplete port of the jsdiff Javascript library.

Links

Usage

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:

  1. Match: { count: <integer>, value: <string> }
  2. Add: { count: <integer>, added: true, value: <string> }
  3. 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"}]

License

MIT

Releasing

  • 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

About

Barebones Myers diff algorithm in Ruby

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages