Method: Unit#normalize!
- Defined in:
- lib/unit/class.rb
#normalize! ⇒ Object
Converts to base units
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/unit/class.rb', line 28 def normalize! if @normalized != self begin last_unit = @unit @unit = [] last_unit.each do |factor, unit, exp| @value *= @system.factor[factor][:value] ** exp if factor != :one if Numeric === unit @unit << [:one, unit, exp] else @unit += Unit.power_unit(@system.unit[unit][:def], exp) end end end while last_unit != @unit reduce! @normalized = self end self end |