Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/si_units/string.rb
Instance Method Summary collapse
- #split_value(value) ⇒ Object
-
#to_unit ⇒ Object
make a string into a unit.
Instance Method Details
#split_value(value) ⇒ Object
9 10 11 |
# File 'lib/si_units/string.rb', line 9 def split_value(value) value.scan(/(\d+\.?\d*)(\w+)/).flatten end |
#to_unit ⇒ Object
make a string into a unit
4 5 6 7 |
# File 'lib/si_units/string.rb', line 4 def to_unit unit_reduced, prefix = *split_value(self) SIUnits::Unit.new(unit_reduced.to_f).convert_to(prefix) end |