Method: Unit.to_unit

Defined in:
lib/unit/class.rb

.to_unit(object, system = nil) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/unit/class.rb', line 299

def to_unit(object, system = nil)
  system ||= Unit.default_system
  case object
  when String, Symbol
    unit = system.parse_unit(object.to_s)
    system.validate_unit(unit)
    Unit.new(1, unit, system)
  when Array
    system.validate_unit(object)
    Unit.new(1, object, system)
  else
    numeric_to_unit(object, system)
  end
end