class Converter
The converter class can take in several different temp units, convert and return them in another. By default it's set to celsius.
Attributes
range[R]
temperature[R]
unit[R]
Public Class Methods
new(_settings)
click to toggle source
# File lib/converter.rb, line 8 def initialize(_settings) @unit = unit @wantedunit = wantedunit end
Public Instance Methods
convertion(temperature)
click to toggle source
The convertion class will take in the @param [temperature] and use that to do the convertion. The current and desired units have to be specified. It'll return the result in the desired unit.
# File lib/converter.rb, line 16 def convertion(temperature) thermostat = Thermostat.new if unit == 'celsius' && wantedunit == 'farenheit' ((temperature - 32) * 0.5556) end if unit == 'farenheit' && wantedunit == 'celsius' ((temperature + 32) / 0.5556) end if unit == 'celsius' && wantedunit == 'kelvin' temperature + 273.15 end if unit == 'kelvin' && wantedunit == 'celsius' temperature + 273.15 end if unit == 'farenheit' && wantedunit == 'kelvin' ((temperature + 459.67) * 0.5556) end if unit == 'kelvin' && wantedunit == 'farenheit' ((temperature - 459.67) / 0.5556) end end