Class: Forecastr::Temperature

Inherits:
Object
  • Object
show all
Defined in:
lib/forecastr/temperature.rb

Instance Method Summary collapse

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_celsiusObject



8
9
10
# File 'lib/forecastr/temperature.rb', line 8

def to_celsius
  (@kelvin - 273.15).round(2)
end

#to_farenheitObject



12
13
14
# File 'lib/forecastr/temperature.rb', line 12

def to_farenheit
  (1.8 * (@kelvin - 273.15) + 32).round(2)
end

#to_sObject



16
17
18
# File 'lib/forecastr/temperature.rb', line 16

def to_s
  "#{to_celsius} °C"
end