Sha256: 55be0159dc9367899c7c57eba20a9a05b7318161e9a4dc31169d8fd86cb786ae

Contents?: true

Size: 851 Bytes

Versions: 2

Compression:

Stored size: 851 Bytes

Contents

module RubyOnAcid

class Factory

  def initialize(*args)
    @minimums = {}
    @maximums = {}
  end

  #Calls get_unit with key to get value between 0.0 and 1.0, then converts that value to be between given minimum and maximum.
  def within(key, minimum, maximum)
    get_unit(key) * (maximum - minimum) + minimum
  end
  
  #Calls get_unit with key to get value between 0.0 and 1.0, then converts that value to be between given minimum and maximum.
  def get(key, options = {})
    @minimums[key] = (options[:min] || @minimums[key] || 0.0)
    @maximums[key] = (options[:max] || @maximums[key] || @minimums[key] > 1.0 ? @minimums[key] + 1.0 : 1.0)
    get_unit(key) * (@maximums[key] - @minimums[key]) + @minimums[key]
  end
  
  #Returns true if get_unit(key) returns greater than 0.5.
  def boolean(key)
    get_unit(key) >= 0.5
  end
  
end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubyonacid-0.1.1 lib/rubyonacid/factory.rb
rubyonacid-0.1.0 lib/rubyonacid/factory.rb