Sha256: 99f8208514a40bc692234d24b571e74e354c3c55f99273053ea9e341f87bfbff

Contents?: true

Size: 678 Bytes

Versions: 3

Compression:

Stored size: 678 Bytes

Contents

require 'rubyonacid/factory'

module RubyOnAcid

class LoopFactory < Factory
  
  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

3 entries across 3 versions & 1 rubygems

Version Path
rubyonacid-0.1.2 lib/rubyonacid/factories/loop.rb
rubyonacid-0.1.1 lib/rubyonacid/factories/loop.rb
rubyonacid-0.1.0 lib/rubyonacid/factories/loop.rb