Class: Fortnox::API::CircularQueue

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fortnox/api/circular_queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(*items) ⇒ CircularQueue

Returns a new instance of CircularQueue.



12
13
14
15
# File 'lib/fortnox/api/circular_queue.rb', line 12

def initialize(*items)
  @queue = [*items]
  @@next_index = random_start_index
end

Instance Method Details

#nextObject



20
21
22
23
24
25
26
27
28
# File 'lib/fortnox/api/circular_queue.rb', line 20

def next
  value = @queue[@@next_index]
  if @@next_index == size - 1
    @@next_index = 0
  else
    @@next_index += 1
  end
  value
end