Sha256: 12e90de4fd3de14b567114c57bb4e12338d263c63706e0f4cbde776fa117254d

Contents?: true

Size: 614 Bytes

Versions: 1

Compression:

Stored size: 614 Bytes

Contents

require 'rubyonacid/factory'

module RubyOnAcid

#A factory that returns a preset value for all keys.
class ConstantFactory < Factory
  
  #A value between 0 and 1 that get_unit will return.
  attr_accessor :value
  def value=(value)
    raise "assigned #{value} to value, must be between -1 and 1" if value < -1 or value > 1
    @value = value
  end
  
  #Takes a hash with all keys supported by Factory, plus these keys and defaults:
  #  :value => 0.0
  def initialize(options = {})
    super
    @value = options[:value] || 0.0
  end
  
  #Returns assigned value.
  def get_unit(key)
    @value
  end

end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubyonacid-0.4.0 lib/rubyonacid/factories/constant.rb