Sha256: f5f10ec1a8d1f6d4c9a7fbf17da3c66039425aeacff41d5f2a43c90af0470a86

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

require 'rubyonacid/factory'

module RubyOnAcid

#A Factory that "pulls" source factory values toward an attractor factory's value.
class AttractionFactory < Factory
  
  #Values from source_factory will be "pulled" toward values from this factory.
  attr_accessor :attractor_factory
  
  #Takes a hash with all keys supported by Factory, plus these keys and defaults:
  #  :attractor_factory => nil
  def initialize(options = {})
    super
    @source_factory = options[:source_factory]
    @attractor_factory = options[:attractor_factory]
  end
  
  #Get a value from the source_factories and a value from the attractor_factory.
  #The source_factories average will be adjusted to be closer to the attractor_factory value.
  #The closer the values are, the greater the adjustment.
  def get_unit(key)
    value = super
    attractor_value = @attractor_factory.get_unit(key)
    distance = attractor_value - value
    value += distance / 2.0
    value
  end

end

end

Version data entries

1 entries across 1 versions & 1 rubygems

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