Class: WeatherData::Temperature::Kelvin

Inherits:
Base
  • Object
show all
Defined in:
lib/weather_data/temperature/kelvin.rb

Instance Attribute Summary

Attributes inherited from Base

#degrees

Instance Method Summary collapse

Methods inherited from Base

#*, #+, #-, #-@, #/, #<=>, #==, #to_f, #to_i

Constructor Details

#initialize(deg) ⇒ Kelvin

Returns a new instance of Kelvin.



6
7
8
9
10
# File 'lib/weather_data/temperature/kelvin.rb', line 6

def initialize(deg)
  super

  @degrees = 0 if @degrees < 0
end

Instance Method Details

#to_celsiusObject



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

def to_celsius
  Celsius.new(degrees - 273.15)
end

#to_fahrenheitObject



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

def to_fahrenheit
  to_celsius.to_fahrenheit
end

#to_kelvinObject



20
21
22
# File 'lib/weather_data/temperature/kelvin.rb', line 20

def to_kelvin
  self
end

#to_sObject



24
25
26
# File 'lib/weather_data/temperature/kelvin.rb', line 24

def to_s
  "#{degrees}"
end