Class: Laser::Cutter::Notching::InfiniteIterator

Inherits:
Struct
  • Object
show all
Defined in:
lib/laser-cutter/notching/path_generator.rb

Overview

Alternating iterator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ InfiniteIterator

Returns a new instance of InfiniteIterator.



19
20
21
22
23
# File 'lib/laser-cutter/notching/path_generator.rb', line 19

def initialize(array)
  self.array = array
  self.calls = 0
  self.next_index = 0
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array

Returns:

  • (Object)

    the current value of array



16
17
18
# File 'lib/laser-cutter/notching/path_generator.rb', line 16

def array
  @array
end

#callsObject

Returns the value of attribute calls.



17
18
19
# File 'lib/laser-cutter/notching/path_generator.rb', line 17

def calls
  @calls
end

#next_indexObject

Returns the value of attribute next_index.



17
18
19
# File 'lib/laser-cutter/notching/path_generator.rb', line 17

def next_index
  @next_index
end

Instance Method Details

#nextObject



25
26
27
28
29
30
31
32
# File 'lib/laser-cutter/notching/path_generator.rb', line 25

def next
  item = self.array[next_index].clone
  self.next_index += 1
  self.next_index %= array.size
  self.calls += 1
  item = yield item, self.calls if block_given?
  item
end