Module: Unite::Conversion

Extended by:
ActiveSupport::Concern
Includes:
Comparison, SiFactor
Included in:
Arithmetic, DerivedUnit, Property, Quantity
Defined in:
lib/unite/conversion.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Fraction

#expanded_denominator, #expanded_numerator, #expression, #expression=, #initialize, #inverse, #reduce, #unit

Methods included from Comparison

#==, #compatible!, #compatible?, #compatible_units

Methods included from Dimension::Integer

#dimension_int, #property, #property_name

Instance Method Details

#convert_to(other) ⇒ Object



20
21
22
23
24
25
# File 'lib/unite/conversion.rb', line 20

def convert_to other
  other = cast_to_unit other
  new_value, new_numerator, new_denominator = converted(other)
  return nil if new_value.nil?
  self.class.new :value => new_value, :numerator => new_numerator, :denominator => new_denominator
end

#convert_to!(other) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/unite/conversion.rb', line 27

def convert_to! other
  other = cast_to_unit other
  compatible! other
  new_value, new_numerator, new_denominator = converted(other)
  self.value = new_value
  self.numerator = new_numerator
  self.denominator = new_denominator
  self
end