Class: OCG::Operator::MIX

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

Overview

OCG::Operator::MIX class.

Constant Summary

Constants inherited from Abstract

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

#reset

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?

Returns:

  • (Boolean)


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

#lastObject

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

#lengthObject

Get options combination length.



66
67
68
# File 'lib/ocg/operator/mix.rb', line 66

def length
  @main_generator.length
end

#nextObject

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_generatorObject

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?

Returns:

  • (Boolean)


61
62
63
# File 'lib/ocg/operator/mix.rb', line 61

def started?
  @main_generator.started?
end