Class: OCG::Operator::AND

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

Overview

OCG::Operator::AND class.

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

Is option combinations generation finished?

Returns:

  • (Boolean)


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

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

#lastObject

Get last option combination result.



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

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

  merge_results left, right
end

#lengthObject

Get options combination length.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ocg/operator/and.rb', line 46

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

Get next option combination result.



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

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

Is option combinations generation started?

Returns:

  • (Boolean)


41
42
43
# File 'lib/ocg/operator/and.rb', line 41

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