Class: Lookout::Diff::Operations

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/lookout-3.0/diff/operations.rb

Overview

Sequence of Operations based on a sequence of Matches. Each match is turned into a Copy, Delete, Insert, or Replace operation based on its relation to other matches in the sequence of matches. Empty copy operations will never be a part of this sequence.

Defined Under Namespace

Classes: Copy, Delete, Insert, Replace

Instance Method Summary collapse

Instance Method Details

# {|operation| ... } ⇒ Object #Enumerator<Operation>

Overloads:

  • # {|operation| ... } ⇒ Object

    Enumerates the operations.

    Yield Parameters:

  • #Enumerator<Operation>

    Returns An Enumerator over the operations.

    Returns:

    • (Enumerator<Operation>)

      An Enumerator over the operations



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lookout-3.0/diff/operations.rb', line 19

def each
  return enum_for(__method__) unless block_given?
  old = new = 0
  matches.each do |match|
    type = if    old < match.old.begin and new < match.new.begin then Replace
           elsif old < match.old.begin                           then Delete
           elsif new < match.new.begin                           then Insert
           else                                                       Copy
           end
    yield type.new(match.old.at(old...match.old.begin),
                   match.new.at(new...match.new.begin)) unless type == Copy
    yield Copy.new(match.old, match.new) unless match.empty?
    old, new = match.old.end + 1, match.new.end + 1
  end
  self
end