class ConvertUnit::Length

Constants

CONVERSION_RATE
UNITS
UNITS_SYMBOL

Attributes

unit[RW]
value[RW]

Public Class Methods

new(value, unit) click to toggle source
Calls superclass method Base::new
# File lib/convert_unit/length.rb, line 13
def initialize(value, unit)
  unit_symbol = Length::UNITS_SYMBOL[unit] || unit
  @conversion_rate_for_one_unit = Length::CONVERSION_RATE
  super(value, unit_symbol, Length::UNITS)
end

Public Instance Methods

to(c_unit) click to toggle source
# File lib/convert_unit/length.rb, line 19
def to(c_unit)
  c_unit.downcase!
  unit_symbol = Length::UNITS_SYMBOL[c_unit] || c_unit
  raise ArgumentError, 'Impossible conversion type' unless Length::UNITS.include?(unit_symbol)
  Length.new(convert_to(unit_symbol), unit_symbol)
end