Class: RubyOnAcid::IncrementFactory

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

Overview

Increments from the minimum value, stopping at the maximum, or decrements from the maximum value, stopping at the minimum.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Factory

#boolean, #choose, #get, #within

Constructor Details

#initialize(interval = 0.001) ⇒ IncrementFactory

Returns a new instance of IncrementFactory.



16
17
18
19
20
21
# File 'lib/rubyonacid/factories/increment.rb', line 16

def initialize(interval = 0.001)
  super
  @start_value = 0.0
  @counters = {}
  @interval = interval
end

Instance Attribute Details

#intervalObject

The amount to increment counters by.



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

def interval
  @interval
end

Instance Method Details

#get_unit(key) ⇒ Object

Increment counter for given key and return it. Constrain between 0 and 1.



24
25
26
27
28
29
30
# File 'lib/rubyonacid/factories/increment.rb', line 24

def get_unit(key)
  @counters[key] ||= @start_value
  @counters[key] += @interval
  @counters[key] = 1.0 if @counters[key] > 1.0
  @counters[key] = 0.0 if @counters[key] < 0.0
  @counters[key]
end