class Alchemist::ConversionCalculator
Attributes
from[R]
parsed_unit[R]
Public Class Methods
new(from, parsed_unit)
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 3 def initialize(from, parsed_unit) @from = from @parsed_unit = parsed_unit end
Public Instance Methods
calculate()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 8 def calculate Measurement.new(value / exponent, unit_name, exponent) end
Private Instance Methods
base()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 35 def base @base ||= BigDecimal(from.base(type).to_s) end
exponent()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 15 def exponent parsed_unit.exponent end
factor()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 43 def factor @factor = Alchemist.library.conversion_base_for(type, unit_name) end
proc_based?()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 31 def proc_based? factor.is_a? Array end
type()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 39 def type @type ||= parsed_unit.guess_type(from) end
unit_name()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 19 def unit_name parsed_unit.unit_name end
value()
click to toggle source
# File lib/alchemist/conversion_calculator.rb, line 23 def value if proc_based? factor[1].call(base) else base / BigDecimal(factor.to_s) end end