class OCG::Operator::MIX

OCG::Operator::MIX class.

Public Class Methods

new(*args) click to toggle source

Initializes current generators.

Calls superclass method OCG::Operator::Abstract::new
# File lib/ocg/operator/mix.rb, line 11
def initialize(*args)
  super

  reset_main_generator
end

Public Instance Methods

finished?() click to toggle source

Is option combinations generation finished?

# File lib/ocg/operator/mix.rb, line 56
def finished?
  @main_generator.finished?
end
initialize_copy(*args) click to toggle source

Initializes copy of current generators.

Calls superclass method OCG::Copyable#initialize_copy
# File lib/ocg/operator/mix.rb, line 18
def initialize_copy(*args)
  super

  reset_main_generator
end
last() click to toggle source

Get last option combination result.

# File lib/ocg/operator/mix.rb, line 48
def last
  left  = @left_generator.last
  right = @right_generator.last

  merge_results left, right
end
length() click to toggle source

Get options combination length.

# File lib/ocg/operator/mix.rb, line 66
def length
  @main_generator.length
end
next() click to toggle source

Get next option combination result.

# 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() click to toggle source

Resets left or right generator based on internal state.

# 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?() click to toggle source

Is option combinations generation started?

# File lib/ocg/operator/mix.rb, line 61
def started?
  @main_generator.started?
end