Class: OCG::Operator::AND

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

Constant Summary

Constants inherited from Abstract

OCG::Operator::Abstract::VARIABLES_TO_COPY

Constants inherited from OCG

DELEGATORS, VARIABLES_TO_COPY, VERSION

Constants included from Copyable

Copyable::VARIABLES_TO_COPY

Instance Method Summary collapse

Methods inherited from Abstract

#initialize, #reset

Methods inherited from OCG

#and, #each, #initialize, #mix, #or, prepare_generator

Methods included from Copyable

#initialize_copy

Constructor Details

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

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


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

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

#lastObject



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

def last
  left  = @left_generator.last
  right = @right_generator.last

  merge_results left, right
end

#lengthObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ocg/operator/and.rb', line 40

def length
  left_length  = @left_generator.length
  right_length = @right_generator.length

  if left_length.zero?
    right_length
  elsif right_length.zero?
    left_length
  else
    left_length * right_length
  end
end

#nextObject



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

def next
  return nil if finished?

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

  right = @right_generator.next

  merge_results left, right
end

#started?Boolean

Returns:

  • (Boolean)


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

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