class JSONThermostat
Public Class Methods
new(settings)
click to toggle source
# File lib/json_thermostat.rb, line 4 def initialize(settings) @settings = JSON.parse(settings) if @settings['unit'] @thermostat = Thermostat.new( @settings['temperature'], @settings['range'], @settings['unit'] ) else @thermostat = Thermostat.new( @settings['temperature'], @settings['range'], 'celsius' ) end end
Public Instance Methods
update(measurement)
click to toggle source
# File lib/json_thermostat.rb, line 17 def update(measurement) @measurement = JSON.parse(measurement) @thermostat.current_value = @measurement['temperature'] if @measurement['unit'] @thermostat.run(@measurement['unit']) else @thermostat.run('celsius') end JSON.generate(cooling: @thermostat.airco, heating: @thermostat.heating) end