class JSONThermostat

Attributes

range[RW]
settings[RW]
temp[RW]
unit[RW]
value[RW]
wanted_value[RW]

Public Class Methods

new(settingjson) click to toggle source
# File lib/json_thermostat.rb, line 5
def initialize(settingjson)
  @settings = JSON.parse(settingjson)
  @wanted_value = unit_conversion(settings['temperature'], settings['unit'])
  @range = unit_conversion(settings['range'], settings['unit']) .abs
end

Public Instance Methods

unit_conversion(value, unit) click to toggle source
# File lib/json_thermostat.rb, line 19
def unit_conversion(value, unit)
  @value = value
  @unit = unit
  if unit == 'fahrenheit'
    return ((value - 32) / 1.8)
  elsif unit == 'kelvin'
    return (value - 273.15)
  else
    return value
  end
end
update(update_value) click to toggle source
# File lib/json_thermostat.rb, line 12
def update(update_value)
  @temp = JSON.parse(update_value)
  updated_temp = unit_conversion(temp['temperature'], temp['unit'])
  Thermostat.checkTemp(updated_temp, wanted_value, range)
end