Method: UnitMeasurements::Unit#conversion_factor
- Defined in:
- lib/unit_measurements/unit.rb
#conversion_factor ⇒ Numeric
Calculates the conversion factor for the unit. This method is recursively invoked to calculate the conversion factor of the unit, if unit conversion value
is specified with respect to the other unit.
This method uses parse_value
method to extract the conversion value and the unit.
148 149 150 151 152 153 154 155 |
# File 'lib/unit_measurements/unit.rb', line 148 def conversion_factor return value if value.is_a?(Numeric) measurement_value, measurement_unit = parse_value(value) conversion_factor = unit_group.unit_for!(measurement_unit).conversion_factor conversion_factor * measurement_value end |