Class: Lookout::Diff::Groups

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

Overview

Sequence of Operations bundled together into Groups that can then be used to show the subsequences that differ, folding away the subsequences that are the same, only keeping some context around the folding points.

Instance Method Summary collapse

Instance Method Details

# {|group| ... } ⇒ Object #Enumerator<Group>

Overloads:

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

    Enumerates the groups of operations.

    Yield Parameters:

  • #Enumerator<Group>

    Returns An Enumerator over the groups of operations.

    Returns:

    • (Enumerator<Group>)

      An Enumerator over the groups of operations



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lookout-3.0/diff/groups.rb', line 21

def each
  return enum_for(__method__) unless block_given?
  saved = nil
  group = Lookout::Diff::Group.new
  operations.each do |operation|
    if saved
      yield saved
      saved = nil
    end
    if group.empty?
      operation = operation >> context
      group << operation
    elsif operation.foldable? context
      saved = group << (operation << context)
      group = Lookout::Diff::Group.new(operation >> context)
    else
      group << operation
    end
  end
  if saved
    yield saved
  elsif not group.empty?
    yield group.fold(context)
  end
  self
end