Class: GeneralUnits::Length

Inherits:
Base::Measurement show all
Defined in:
lib/general_units/units/length.rb

Defined Under Namespace

Classes: Unit

Instance Attribute Summary

Attributes inherited from Base::Measurement

#amount, #unit

Instance Method Summary collapse

Methods inherited from Base::Measurement

#%, #*, #+, #-, #-@, #/, #<, #<=, #<=>, #==, #>, #>=, #abs, #attributes, #coerce, #div, #divmod, #eql?, i18n_class_key, #i18n_delimeter, i18n_format_key, i18n_key, i18n_scope_key, #initialize, #inspect, #measurement, #modulo, #negative?, #nonzero?, #positive?, #remainder, #rounded, select_units, #to_s, #zero?

Constructor Details

This class inherits a constructor from GeneralUnits::Base::Measurement

Instance Method Details

#convert_to(unit) ⇒ Object



18
19
20
21
22
23
# File 'lib/general_units/units/length.rb', line 18

def convert_to(unit)
  if convert_unit = valid_unit?(unit)
    convert_amount = amount * @unit.millimeters/convert_unit.millimeters
    Length.new(convert_amount, unit)
  end
end

#to_volume(unit_code) ⇒ Object



25
26
27
28
# File 'lib/general_units/units/length.rb', line 25

def to_volume(unit_code)
  volume = GeneralUnits::Volume.new(amount, :"cubic_#{unit.code}")
  unit_code ? volume.convert_to(unit_code) : volume
end