class JSONThermostat
Attributes
range[R]
temperature[R]
unit[R]
unit_m[R]
update[R]
Public Class Methods
new(settings)
click to toggle source
# File lib/json_thermostat.rb, line 8 def initialize(settings) @temperature = JSON.parse(settings)['temperature'] @unit = JSON.parse(settings)['unit'] @range = JSON.parse(settings)['range'] / 2 end
Public Instance Methods
heat_or_cool()
click to toggle source
# File lib/json_thermostat.rb, line 22 def heat_or_cool thermo = { cooling: false, heating: false } if Thermostat.new.airco_temperature(@temperature_m, temperature, range) thermo[:cooling] = true end if Thermostat.new.heating_temperature(@temperature_m, temperature, range) thermo[:heating] = true end JSON.generate(thermo) end
unit_check()
click to toggle source
# File lib/json_thermostat.rb, line 35 def unit_check if (unit == 'celsius' || unit.to_s.empty?) && unit_m == 'kelvin' @temperature_m = Converter.new.ktoc(@temperature_m) end if (unit == 'celsius' || unit.to_s.empty?) && unit_m == 'fahrenheit' @temperature_m = Converter.new.ftoc(@temperature_m) end if unit == 'kelvin' && (unit_m == 'celsius' || unit_m.to_s.empty?) @temperature_m = Converter.new.ctok(@temperature_m) end if unit == 'kelvin' && unit_m == 'fahrenheit' @temperature_m = Converter.new.ftok(@temperature_m) end if unit == 'fahrenheit' && unit_m == 'kelvin' @temperature_m = Converter.new.ktof(@temperature_m) end if unit == 'fahrenheit' && (unit_m == 'celsius' || unit_m.to_s.empty?) @temperature_m = Converter.new.ctof(@temperature_m) end end