Sha256: e5db911fa940905cf66f964e46abb9b0c11b26cafe1663b13f9a1839a4eec357

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

require 'rubyonacid/factory'

module RubyOnAcid

#Scales values from source factories according to how close they are to a target value.
class ProximityFactory < Factory
  
  #The target value.
  attr_accessor :target
  
  #Takes a hash with all keys supported by Factory, plus these keys and defaults:
  #  :target => rand()
  def initialize(options = {})
    super
    @target = options[:target] || rand
  end

  #Return values approach 1.0 as the values from the source factories approach the target value.
  #Values approach zero as the source factory values approach a distance of 1.0 from the target value.
  def get_unit(key)
    1.0 - (super - @target).abs
  end
  
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

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