Class: RubyOnAcid::LoopFactory

Inherits:
Factory
  • Object
show all
Defined in:
lib/rubyonacid/factories/loop.rb

Overview

Loops from the minimum value to the maximum and around again.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Factory

#boolean, #choose, #get, #within

Constructor Details

#initialize(interval = 0.01) ⇒ LoopFactory

Returns a new instance of LoopFactory.



15
16
17
18
19
# File 'lib/rubyonacid/factories/loop.rb', line 15

def initialize(interval = 0.01)
  super
  @counters = {}
  @interval = interval
end

Instance Attribute Details

#intervalObject

An amount between 0 and 1 to increment counters by.



9
10
11
# File 'lib/rubyonacid/factories/loop.rb', line 9

def interval
  @interval
end

Instance Method Details

#get_unit(key) ⇒ Object

Increment counter for key, looping it around to opposite side if it exits boundary.



22
23
24
25
26
27
28
# File 'lib/rubyonacid/factories/loop.rb', line 22

def get_unit(key)
  @counters[key] ||= 0
  @counters[key] += @interval
  @counters[key] = @counters[key] - 1.0 if @counters[key] > 1
  @counters[key] = @counters[key] + 1.0 if @counters[key] < 0
  @counters[key]
end