Sha256: 9323274d4e8b7f07dabce201f4fa3cf4d96a4ef2cf5b968ec58e45dcb3af074b
Contents?: true
Size: 718 Bytes
Versions: 1
Compression:
Stored size: 718 Bytes
Contents
require 'rubyonacid/factory' module RubyOnAcid class LoopFactory < Factory #The amount to increment counters by. attr_accessor :interval def interval=(value) raise "assigned #{value} to interval, must be between -1 and 1" if value < -1 or value > 1 @interval = value end def initialize(interval = 0.01) super @counters = {} @interval = interval end #Increment counter for key, looping it around to opposite side if it exits boundary. 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubyonacid-0.2.0 | lib/rubyonacid/factories/loop.rb |