Class: JSONThermostat
- Inherits:
-
Object
- Object
- JSONThermostat
- Defined in:
- lib/json_thermostat.rb
Overview
result = thermostat.update measurement
Instance Attribute Summary collapse
-
#range ⇒ Object
Returns the value of attribute range.
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#wanted_value ⇒ Object
Returns the value of attribute wanted_value.
Instance Method Summary collapse
-
#converter ⇒ Object
Uses the Converter class to make a converter instance that can be used.
-
#initialize(testjson) ⇒ JSONThermostat
constructor
Takes in a JSON object and parses the different values.
-
#thermo ⇒ Object
Uses the Thermostat class to make a thermostat instance to process input.
-
#update(testjson) ⇒ Object
Takes in JSON object to update the current temperature.
Constructor Details
#initialize(testjson) ⇒ JSONThermostat
Takes in a JSON object and parses the different values. Uses [converter] method for converter instance.
18 19 20 21 22 23 |
# File 'lib/json_thermostat.rb', line 18 def initialize() @unit = "celsius" @range = 1.0; @wanted_value = 21.0; end |
Instance Attribute Details
#range ⇒ Object
Returns the value of attribute range.
12 13 14 |
# File 'lib/json_thermostat.rb', line 12 def range @range end |
#unit ⇒ Object
Returns the value of attribute unit.
12 13 14 |
# File 'lib/json_thermostat.rb', line 12 def unit @unit end |
#wanted_value ⇒ Object
Returns the value of attribute wanted_value.
12 13 14 |
# File 'lib/json_thermostat.rb', line 12 def wanted_value @wanted_value end |
Instance Method Details
#converter ⇒ Object
Uses the Converter class to make a converter instance that can be used.
35 36 37 |
# File 'lib/json_thermostat.rb', line 35 def converter @converter ||= Converter.new end |
#thermo ⇒ Object
Uses the Thermostat class to make a thermostat instance to process input.
41 42 43 44 |
# File 'lib/json_thermostat.rb', line 41 def thermo = { wanted_value: wanted_value, range: range } @thermo ||= Thermostat.new() end |
#update(testjson) ⇒ Object
Takes in JSON object to update the current temperature. Uses thermo instance to update the thermostat. Uses [thermo] method for thermo instance.
51 52 53 54 55 56 |
# File 'lib/json_thermostat.rb', line 51 def update(testjson) parsed = JSON.parse(testjson) args = { unit: parsed['unit'], value: parsed['temperature'] } thermo.update_current(converter.temp_to_celcius(args)) thermo.update_thermo end |