Module: Systeme
- Includes:
- Conversions, Imperial, International, Length, Localize, Metric
- Defined in:
- lib/systeme.rb,
lib/systeme/length.rb,
lib/systeme/metric.rb,
lib/systeme/imperial.rb,
lib/systeme/localize.rb,
lib/systeme/conversions.rb,
lib/systeme/registration.rb,
lib/systeme/international.rb
Defined Under Namespace
Modules: Conversions, Imperial, International, Length, Localize, Metric, Registration
Class Method Summary collapse
Methods included from Conversions
Methods included from Length
Methods included from Imperial
Methods included from Metric
Methods included from Localize
Methods included from International
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Systeme::Conversions
Class Method Details
.parse(string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/systeme.rb', line 17 def self.parse(string) return nil if (!string || !string.match(/\d/)) string.gsub!(/ */, '').gsub!(/([a-zA-Z])(\d)/, '\1 \2') parts = string.split(' ') total = parts.inject(0) do |total, part| value = part.to_f label = ((l = part.match(/([a-zA-Z]+)/)) ? l[1] : "m") total += (value.respond_to?(label) ? value.send(label) : 0) end return total end |