Class: Forecastr::Temperature
- Inherits:
-
Object
- Object
- Forecastr::Temperature
- Defined in:
- lib/forecastr/temperature.rb
Instance Method Summary collapse
-
#initialize(kelvin) ⇒ Temperature
constructor
A new instance of Temperature.
- #to_celsius ⇒ Object
- #to_farenheit ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(kelvin) ⇒ Temperature
Returns a new instance of Temperature.
4 5 6 |
# File 'lib/forecastr/temperature.rb', line 4 def initialize(kelvin) @kelvin = kelvin end |
Instance Method Details
#to_celsius ⇒ Object
8 9 10 |
# File 'lib/forecastr/temperature.rb', line 8 def to_celsius (@kelvin - 273.15).round(2) end |
#to_farenheit ⇒ Object
12 13 14 |
# File 'lib/forecastr/temperature.rb', line 12 def to_farenheit (1.8 * (@kelvin - 273.15) + 32).round(2) end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/forecastr/temperature.rb', line 16 def to_s "#{to_celsius} °C" end |