Class: JSONThermostat

Inherits:
Object
  • Object
show all
Defined in:
lib/json_thermostat.rb

Overview

result = thermostat.update measurement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(testjson) ⇒ JSONThermostat

Takes in a JSON object and parses the different values. Uses [converter] method for converter instance.

Parameters:

  • input (JSON)

    JSON file with unit, range and wanted value



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

#rangeObject

Returns the value of attribute range.



12
13
14
# File 'lib/json_thermostat.rb', line 12

def range
  @range
end

#unitObject

Returns the value of attribute unit.



12
13
14
# File 'lib/json_thermostat.rb', line 12

def unit
  @unit
end

#wanted_valueObject

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

#converterObject

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

#thermoObject

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
  message = { wanted_value: wanted_value, range: range }
  @thermo ||= Thermostat.new(message)
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.

Parameters:

  • input (JSON)

    JSON file with current value



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