Method: SimpleUnits::Unit#initialize

Defined in:
lib/simple_units/unit.rb

#initialize(value, units) ⇒ Unit

Returns a new instance of Unit.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_units/unit.rb', line 18

def initialize(value, units)
  @value = value
  case units.class.to_s
  when "String", "Symbol"
    @composite = SimpleUnits::Composite.from_string units.to_s
  when "SimpleUnits::Context"
    @composite = SimpleUnits::Composite.from_context units
  when "SimpleUnits::Composite"
    @composite = units
  else
    raise UnknownUnitError.new("#{units} is a #{units.class}")
  end
  
end