Class: RubyOnAcid::RoundingFactory

Inherits:
Factory
  • Object
show all
Defined in:
lib/rubyonacid/factories/rounding.rb

Overview

Rounds values from a source factory, useful for clustering values into groups.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nearestObject

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_factoryObject

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