Class: OCG::Operator::AND

Inherits:
Abstract show all
Defined in:
lib/ocg/operator/and.rb

Constant Summary

Constants inherited from OCG

DELEGATORS, VERSION

Instance Method Summary collapse

Methods inherited from Abstract

#initialize, #reset

Methods inherited from OCG

#and, #initialize, #mix, #or, prepare_generator, #to_a

Constructor Details

This class inherits a constructor from OCG::Operator::Abstract

Instance Method Details

#finished?Boolean



35
36
37
# File 'lib/ocg/operator/and.rb', line 35

def finished?
  @left_generator.finished? && @right_generator.finished?
end

#lastObject



22
23
24
25
26
27
28
29
# File 'lib/ocg/operator/and.rb', line 22

def last
  left_last  = @left_generator.last
  right_last = @right_generator.last

  return nil if left_last.nil? || right_last.nil?

  left_last.merge right_last
end

#lengthObject



39
40
41
# File 'lib/ocg/operator/and.rb', line 39

def length
  @left_generator.length * @right_generator.length
end

#nextObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ocg/operator/and.rb', line 9

def next
  return nil if finished?

  if @right_generator.finished?
    @right_generator.reset
    @left_generator.next.merge @right_generator.next
  else
    left_last = @left_generator.last
    left_last = @left_generator.next if left_last.nil?
    left_last.merge @right_generator.next
  end
end

#started?Boolean



31
32
33
# File 'lib/ocg/operator/and.rb', line 31

def started?
  @left_generator.started? || @right_generator.started?
end