Module: WeatherData::Temperature
- Extended by:
- Temperature
- Included in:
- Temperature
- Defined in:
- lib/weather_data/temperature.rb,
lib/weather_data/temperature/base.rb,
lib/weather_data/temperature/kelvin.rb,
lib/weather_data/temperature/celsius.rb,
lib/weather_data/temperature/fahrenheit.rb
Defined Under Namespace
Modules: HelperMethods Classes: Base, Celsius, Fahrenheit, Kelvin
Constant Summary collapse
- CELSIUS =
:C
- FAHRENHEIT =
:F
- KELVIN =
:K
Instance Method Summary collapse
Instance Method Details
#parse(s) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/weather_data/temperature.rb', line 16 def parse(s) degrees, units = s.match(/([+-]?\d+(?:\.\d+)?)\s*(°?#{CELSIUS}|°?#{FAHRENHEIT}|#{KELVIN})\b/u).to_a[1..2] raise ArgumentError.new(%Q{"#{s}" doesn't contain temperature}) unless degrees && units units_class(units).new(degrees.to_f) end |