Class: Lookout::Diff::Algorithms::Difflib
- Includes:
- Enumerable
- Defined in:
- lib/lookout/diff/algorithms/difflib.rb
Defined Under Namespace
Classes: Position
Instance Method Summary collapse
- #each {|current| ... } ⇒ Object
-
#initialize(from, to, &is_junk) ⇒ Difflib
constructor
A new instance of Difflib.
Constructor Details
#initialize(from, to, &is_junk) ⇒ Difflib
Returns a new instance of Difflib.
8 9 10 |
# File 'lib/lookout/diff/algorithms/difflib.rb', line 8 def initialize(from, to, &is_junk) @from, @to, @is_junk = from, to, is_junk end |
Instance Method Details
#each {|current| ... } ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lookout/diff/algorithms/difflib.rb', line 12 def each current = Lookout::Diff::Match.new(Lookout::Diff::Range.new(@from, 0...0), Lookout::Diff::Range.new(@to, 0...0)) stack = [Position.origin(@from, @to, &@is_junk)] until stack.empty? case item = stack.pop when Position match = item.match next if match.empty? stack.push item.begin_after(match) if item.ends_after? match stack.push match stack.push item.end_before(match) if item.begins_before? match when Lookout::Diff::Match if current.touches? item current += item else yield current unless current.empty? current = item end end end yield current unless current.empty? yield Lookout::Diff::Match.new(current.from.at(@from.size...@from.size), current.to.at(@to.size...@to.size)) self end |