Class: JSONThermostat
- Inherits:
-
Object
- Object
- JSONThermostat
- Defined in:
- lib/json_thermostat.rb
Instance Method Summary collapse
- #converten ⇒ Object
-
#initialize(json) ⇒ JSONThermostat
constructor
A new instance of JSONThermostat.
- #update(json) ⇒ Object
Constructor Details
#initialize(json) ⇒ JSONThermostat
Returns a new instance of JSONThermostat.
6 7 8 |
# File 'lib/json_thermostat.rb', line 6 def initialize(json) @value = JSON.parse(json) end |
Instance Method Details
#converten ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/json_thermostat.rb', line 18 def converten cur = ConvertTemp.new @jsonvalue['temperature'], @jsonvalue['unit'] wan = ConvertTemp.new @value['temperature'], @value['unit'] ran = ConvertTemp.new @value['range'], @value['unit'] thermostat = Thermostat.new(cur.conv(@uni), wan.conv(@uni), ran.conv(@uni)) thermostat.state end |
#update(json) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/json_thermostat.rb', line 10 def update(json) @jsonvalue = JSON.parse(json) @jsonvalue['unit'] = 'celsius' if @jsonvalue['unit'].nil? @value['unit'] = 'celsius' if @value['unit'].nil? @uni = @value['unit'] converten end |