module H::Units
Constants
- UNIT_SYN
Public Class Methods
denormalize_units(u)
click to toggle source
Convert a units expression to the format to be presented to the user
# File lib/h/units.rb, line 41 def denormalize_units(u) if u.blank? u = nil else u = u.to_s.gsub('**','^').tr('*',' ') end u end
normalize_units(u)
click to toggle source
Convert a units expression to a Ruby expression valid for units-syste
# File lib/h/units.rb, line 24 def normalize_units(u) if u.blank? u = nil else u = u.to_s u = UNIT_SYN[u] || u u = u.to_s.gsub('^','**').tr(' ','*') begin ::Units.u(u) rescue u = nil end end u end
valid?(u)
click to toggle source
# File lib/h/units.rb, line 18 def valid?(u) u = normalize_units(u) u && ::Units.u(u) rescue nil end