Project

myers_diff

0.0
No commit activity in last 3 years
No release in over 3 years
Implementation of Myers 1986 text diff algorithm that started as a port of the jsdiff project with plans to branch out to human-friendly diffs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

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