Class: RubyOnAcid::RoundingFactory
- Defined in:
- lib/rubyonacid/factories/rounding.rb
Overview
Rounds values from a source factory, useful for clustering values into groups.
Instance Attribute Summary collapse
-
#nearest ⇒ Object
Source values will be rounded to the nearest multiple of this value.
-
#source_factory ⇒ Object
Factory to get values from.
Instance Method Summary collapse
- #get_unit(key) ⇒ Object
-
#initialize(source_factory = nil, nearest = 0.1) ⇒ RoundingFactory
constructor
A new instance of RoundingFactory.
Methods inherited from Factory
#boolean, #choose, #get, #within
Constructor Details
#initialize(source_factory = nil, nearest = 0.1) ⇒ RoundingFactory
Returns a new instance of RoundingFactory.
13 14 15 16 17 |
# File 'lib/rubyonacid/factories/rounding.rb', line 13 def initialize(source_factory = nil, nearest = 0.1) super @source_factory = source_factory @nearest = nearest end |
Instance Attribute Details
#nearest ⇒ Object
Source values will be rounded to the nearest multiple of this value.
11 12 13 |
# File 'lib/rubyonacid/factories/rounding.rb', line 11 def nearest @nearest end |
#source_factory ⇒ Object
Factory to get values from.
9 10 11 |
# File 'lib/rubyonacid/factories/rounding.rb', line 9 def source_factory @source_factory end |
Instance Method Details
#get_unit(key) ⇒ Object
19 20 21 |
# File 'lib/rubyonacid/factories/rounding.rb', line 19 def get_unit(key) round_to(@source_factory.get_unit(key), @nearest) end |