thermostat_Elise_DeSmet 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32e4d2b6d3920e8ae9059d8aa6cee4b38a2888b0
4
- data.tar.gz: 1da68595d89fd641bc7b0c2db069d152d6ec00b3
3
+ metadata.gz: 754c9f84f61604ac04f926962b25f209a42f0e37
4
+ data.tar.gz: 9f63695938dfc4784efff5adfe89b7cfe0c413ce
5
5
  SHA512:
6
- metadata.gz: 2f434062dd0cada2d273ae0c8e610aa89d6cdb575fc5e3936d350b844592dbee0e5ab2d55ef4d8c28a419253dfd5e8ceda4ed08cfe4934c24a17126475ea2b78
7
- data.tar.gz: 906a2f30afb86632333d480aba5f5e74012714ee14b54826d1caa38cd284b2af84e8c1c9ea175550298514f84df05f276a702cf906e6a452d45d83d9ece54749
6
+ metadata.gz: 63a674e137255776eb0e46e2443d2f4520f15d622ae64eb7f0d814ce5e8e5619256bba33c9cb63793409735764dacc3da34f395d5bffc983558341b343b36797
7
+ data.tar.gz: a1d2e50c6c0684f800461f259c8df16fb2cff50a9eac48ecc74a37f3925cbc50f67c8ca15ea8d86d980317559af8eac520bd4d47952c8c3e0d663a7321de7bc9
@@ -1,4 +1,18 @@
1
+ # Convert class will convert temperature in
2
+ # different units.
3
+
1
4
  class Convert
5
+ # Convert method will loop over units and will
6
+ # check if unit is nil, celsius, kelvin or fahrenheit.
7
+ # It will convert the temperature
8
+ # in celsius, kelvin or fahrenheit
9
+ # @param [String] some wanted values:
10
+ # * :unit [String] The unit of the temperature
11
+ # * :temperature [Double] The value of the temperature
12
+ # @return [Double] the resulting temperature
13
+ # @example
14
+ # convert.convert(86, 'fahrenheit')
15
+ # returns: 30
2
16
  def convert(temperature, unit)
3
17
  return temperature if unit.nil?
4
18
  return temperature if unit == 'celsius'
@@ -4,6 +4,9 @@ require 'convert.rb'
4
4
 
5
5
  class JSONThermostat
6
6
  attr_reader :thermostat, :convert
7
+ # Initialize method that created new convert object,
8
+ # converts the temperature and gives values to thermostat
9
+ # @param setting [String] gets the settings in string
7
10
  def initialize(settings = ' ')
8
11
  obj = JSON.parse(settings)
9
12
  convert = Convert.new
@@ -11,6 +14,11 @@ class JSONThermostat
11
14
  @thermostat = Thermostat.new(temperature, temperature, obj['range'])
12
15
  end
13
16
 
17
+ # The update method will parse the json input, it will
18
+ # get the temperature and unit.
19
+ # A new convert object is made and it is being convert
20
+ # and checked.
21
+ # @param json [String] gets a json string with a temperature and unit
14
22
  def update(json = ' ')
15
23
  obj = JSON.parse(json)
16
24
  temperature = obj['temperature']
@@ -19,9 +27,11 @@ class JSONThermostat
19
27
  temperature = convert.convert(obj['temperature'], obj['unit'])
20
28
  @thermostat.put_temperature(temperature)
21
29
  @thermostat.check
30
+ return generate_Json
22
31
  end
23
32
 
24
- def generateJson
33
+ # This method will generate Json values
34
+ def generate_Json
25
35
  JSON.generate(cooling: @thermostat.airco, heating: @thermostat.heating)
26
36
  end
27
37
  end
@@ -1,26 +1,45 @@
1
1
  class Thermostat
2
2
  attr_accessor :current_value, :wanted_value, :range, :heating, :airco
3
+ # The initialize method makes a thermostat
4
+ # @param [Double] Json object that contains following values
5
+ # * :current_value [Double] The temperature in the room
6
+ # * :wanted_value [Double] The temperature that is wanted in the room
7
+ # * :range [Double]The upper and under margin of the temperature
3
8
  def initialize(current_value = 0.0, wanted_value = 0.0, range = 0.0)
4
9
  @current_value = current_value
5
10
  @wanted_value = wanted_value
6
11
  @range = range / 2
7
12
  end
8
13
 
14
+ # Heat method will set the heating on and airco off
15
+ # when temperature is bellow the wanted value
9
16
  def heat
10
17
  @heating = true
11
18
  @airco = false
12
19
  end
13
20
 
21
+ # Cool method will set the airco on and heating off
22
+ # when temperature is above the wanted value
14
23
  def cool
15
24
  @heating = false
16
25
  @airco = true
17
26
  end
18
27
 
28
+ # The off method will turn off the heating and
29
+ # airco
19
30
  def off
20
31
  @heating = false
21
32
  @airco = false
22
33
  end
23
34
 
35
+ # This method wil check the input values: current value,
36
+ # wanted value and the range.
37
+ # When the current value is larger than the wanted value
38
+ # (plus the range), the cool method is being called.
39
+ # If the current value is smaller than the wanted value
40
+ # (minus the range), the heat method is being called.
41
+ # Otherwise the thermostat is putted off.
42
+ # @return [String] the thermostat status
24
43
  def check
25
44
  if @current_value > (@wanted_value + @range)
26
45
  cool
@@ -34,6 +53,8 @@ class Thermostat
34
53
  end
35
54
  end
36
55
 
56
+ # The put_temperature methode will get the temperature
57
+ # from the input values
37
58
  def put_temperature(temperature)
38
59
  @current_value = temperature
39
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thermostat_Elise_DeSmet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elise De Smet