Class: Lookout::Diff::Groups

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

Instance Method Summary collapse

Constructor Details

#initialize(operations, context = 3) ⇒ Groups

Returns a new instance of Groups.



6
7
8
# File 'lib/lookout/diff/groups.rb', line 6

def initialize(operations, context = 3)
  @operations, @context = operations, context
end

Instance Method Details

#eachObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lookout/diff/groups.rb', line 10

def each
  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 * 2
      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
end