Class: OCG::Operator::MIX
- Defined in:
- lib/ocg/operator/mix.rb
Overview
OCG::Operator::MIX class.
Constant Summary
Constants inherited from Abstract
Constants inherited from OCG
DELEGATORS, VARIABLES_TO_COPY, VERSION
Constants included from Copyable
Instance Method Summary collapse
-
#finished? ⇒ Boolean
Is option combinations generation finished?.
-
#initialize(*args) ⇒ MIX
constructor
Initializes current generators.
-
#initialize_copy(*args) ⇒ Object
Initializes copy of current generators.
-
#last ⇒ Object
Get last option combination result.
-
#length ⇒ Object
Get options combination length.
-
#next ⇒ Object
Get next option combination result.
-
#reset_main_generator ⇒ Object
Resets left or right generator based on internal state.
-
#started? ⇒ Boolean
Is option combinations generation started?.
Methods inherited from Abstract
Methods inherited from OCG
#and, #each, #mix, #or, prepare_generator
Constructor Details
#initialize(*args) ⇒ MIX
Initializes current generators.
11 12 13 14 15 |
# File 'lib/ocg/operator/mix.rb', line 11 def initialize(*args) super reset_main_generator end |
Instance Method Details
#finished? ⇒ Boolean
Is option combinations generation finished?
56 57 58 |
# File 'lib/ocg/operator/mix.rb', line 56 def finished? @main_generator.finished? end |
#initialize_copy(*args) ⇒ Object
Initializes copy of current generators.
18 19 20 21 22 |
# File 'lib/ocg/operator/mix.rb', line 18 def initialize_copy(*args) super reset_main_generator end |
#last ⇒ Object
Get last option combination result.
48 49 50 51 52 53 |
# File 'lib/ocg/operator/mix.rb', line 48 def last left = @left_generator.last right = @right_generator.last merge_results left, right end |
#length ⇒ Object
Get options combination length.
66 67 68 |
# File 'lib/ocg/operator/mix.rb', line 66 def length @main_generator.length end |
#next ⇒ Object
Get next option combination result.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ocg/operator/mix.rb', line 35 def next return nil if finished? @left_generator.reset if @left_generator.finished? @right_generator.reset if @right_generator.finished? left = @left_generator.next right = @right_generator.next merge_results left, right end |
#reset_main_generator ⇒ Object
Resets left or right generator based on internal state.
25 26 27 28 29 30 31 32 |
# File 'lib/ocg/operator/mix.rb', line 25 def reset_main_generator @main_generator = if @right_generator.length > @left_generator.length @right_generator else @left_generator end end |
#started? ⇒ Boolean
Is option combinations generation started?
61 62 63 |
# File 'lib/ocg/operator/mix.rb', line 61 def started? @main_generator.started? end |