class JSONThermostat
Attributes
convert[R]
thermostat[R]
Public Class Methods
new(settings = ' ')
click to toggle source
Initialize method that created new convert object, converts the temperature and gives values to thermostat @param setting [String] gets the settings in string
# File lib/json_thermostat.rb, line 10 def initialize(settings = ' ') obj = JSON.parse(settings) convert = Convert.new temperature = convert.convert(obj['temperature'], obj['unit']) @thermostat = Thermostat.new(temperature, temperature, obj['range']) end
Public Instance Methods
generate_Json()
click to toggle source
This method will generate Json values
# File lib/json_thermostat.rb, line 34 def generate_Json JSON.generate(cooling: @thermostat.airco, heating: @thermostat.heating) end
update(json = ' ')
click to toggle source
The update method will parse the json input, it will get the temperature and unit. A new convert object is made and it is being convert and checked. @param json [String] gets a json string with a temperature and unit
# File lib/json_thermostat.rb, line 22 def update(json = ' ') obj = JSON.parse(json) temperature = obj['temperature'] unit = obj['unit'] convert = Convert.new temperature = convert.convert(obj['temperature'], obj['unit']) @thermostat.put_temperature(temperature) @thermostat.check return generate_Json end