Class: RubyOnAcid::CombinationFactory
- Defined in:
- lib/rubyonacid/factories/combination.rb
Constant Summary collapse
- ADD =
Causes get_unit value of all source_factories to be added together.
:add
- SUBTRACT =
Takes the get_unit value of the first of the source_factories and subtracts the get_unit value of all subsequent ones.
:subtract
- MULTIPLY =
Causes get_unit value of all source_factories to be multiplied.
:multiply
- DIVIDE =
Takes the get_unit value of the first of the source_factories and divides the result by the get_unit value of all subsequent ones.
:divide
- CONSTRAIN =
Causes get_unit values above 1 to be truncated at 1 and values below 0 to be truncated at 0.
:constrain
- WRAP =
Causes get_unit values above 1 to wrap to 0 and values below 0 to wrap to 1.
:wrap
Instance Attribute Summary collapse
-
#constrain_mode ⇒ Object
The method get_unit will use to constrain values between 0 and 1.
-
#operation ⇒ Object
The operation get_unit will perform.
-
#source_factories ⇒ Object
An array of factories to be queried by get_unit.
Instance Method Summary collapse
-
#get_unit(key) ⇒ Object
Queries all source_factories with given key and combines their return values with the set operation.
-
#initialize(options = {}) ⇒ CombinationFactory
constructor
A new instance of CombinationFactory.
Methods inherited from Factory
#boolean, #choose, #get, #within
Constructor Details
#initialize(options = {}) ⇒ CombinationFactory
Returns a new instance of CombinationFactory.
27 28 29 30 31 32 |
# File 'lib/rubyonacid/factories/combination.rb', line 27 def initialize( = {}) super @source_factories = [:source_factories] || [] @operation = [:operation] || ADD @constrain_mode = [:constrain_mode] || WRAP end |
Instance Attribute Details
#constrain_mode ⇒ Object
The method get_unit will use to constrain values between 0 and 1.
25 26 27 |
# File 'lib/rubyonacid/factories/combination.rb', line 25 def constrain_mode @constrain_mode end |
#operation ⇒ Object
The operation get_unit will perform.
23 24 25 |
# File 'lib/rubyonacid/factories/combination.rb', line 23 def operation @operation end |
#source_factories ⇒ Object
An array of factories to be queried by get_unit.
21 22 23 |
# File 'lib/rubyonacid/factories/combination.rb', line 21 def source_factories @source_factories end |
Instance Method Details
#get_unit(key) ⇒ Object
Queries all source_factories with given key and combines their return values with the set operation. Values will be constrained between 0 and 1 with the set constrain_mode.
36 37 38 39 |
# File 'lib/rubyonacid/factories/combination.rb', line 36 def get_unit(key) combined_value = combine(key) constrain(combined_value) end |