Class: OCG::Operator::MIX

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

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

Returns a new instance of MIX.



9
10
11
12
13
# File 'lib/ocg/operator/mix.rb', line 9

def initialize(*args)
  super

  reset_main_generator
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ocg/operator/mix.rb', line 51

def finished?
  @main_generator.finished?
end

#initialize_copy(*args) ⇒ Object



15
16
17
18
19
# File 'lib/ocg/operator/mix.rb', line 15

def initialize_copy(*args)
  super

  reset_main_generator
end

#lastObject



38
39
40
41
42
43
44
45
# File 'lib/ocg/operator/mix.rb', line 38

def last
  left_last  = @left_generator.last
  right_last = @right_generator.last

  return nil if left_last.nil? || right_last.nil?

  left_last.merge right_last
end

#lengthObject



55
56
57
# File 'lib/ocg/operator/mix.rb', line 55

def length
  @main_generator.length
end

#nextObject



30
31
32
33
34
35
36
# File 'lib/ocg/operator/mix.rb', line 30

def next
  return nil if finished?

  @left_generator.reset if @left_generator.finished?
  @right_generator.reset if @right_generator.finished?
  @left_generator.next.merge @right_generator.next
end

#reset_main_generatorObject



21
22
23
24
25
26
27
28
# File 'lib/ocg/operator/mix.rb', line 21

def reset_main_generator
  @main_generator =
    if @right_generator.length > @left_generator.length
      @right_generator
    else
      @left_generator
    end
end

#started?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ocg/operator/mix.rb', line 47

def started?
  @main_generator.started?
end