thermostat_drees_camertijn 0.3.C
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/json_thermostat.rb +20 -0
- data/lib/temp_unit.rb +17 -0
- data/lib/thermostat.rb +29 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 06ed58b54aac7e3be67bc27ce3ba494df2d09313144047045ceae6723d2a829a
|
4
|
+
data.tar.gz: f1c24050d0cdc719b563947b5264ca1477ebd7df43a467abeb7c1dad7ee24a95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90d95552b26aac24e2158f33249c216a3c114f77aac2f62e46a07668a2a721b53865ae17e0d08ecbead3007b0d151c140f1ceaf066baac729b9a1abbb89c00ca
|
7
|
+
data.tar.gz: 68f127776aef08ade916e953f570cd8c6f3d989035b3d51812a683b03374d737d54dfdf918fd13c0782e67e5471ef7e6c2b5b13f90116e998528ee84256f0c4e
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'thermostat'
|
3
|
+
require 'temp_unit'
|
4
|
+
|
5
|
+
class JSONThermostat
|
6
|
+
attr_accessor :string, :interface, :unit, :temp
|
7
|
+
def initialize(string = "World" )
|
8
|
+
value = JSON.parse(string) # returns a hash
|
9
|
+
@interface = Thermostat.new(unit.calculate,value["range"])
|
10
|
+
unit = TempUnit.new(value["unit"],value["temperature"])
|
11
|
+
end
|
12
|
+
def update measurement
|
13
|
+
value = JSON.parse(measurement) # returns a hash
|
14
|
+
unit = TempUnit.new(value["unit"],value["temperature"])
|
15
|
+
interface.update (unit.calculate)
|
16
|
+
# return json string
|
17
|
+
result = JSON.generate({cooling: interface.cooling, heating: interface.heating})
|
18
|
+
return result
|
19
|
+
end
|
20
|
+
end
|
data/lib/temp_unit.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class TempUnit
|
2
|
+
attr_accessor :curent_unit, :value, :wanted_value
|
3
|
+
def initialize(curent_unit = "celsius", value = 0 )
|
4
|
+
@curent_unit = curent_unit
|
5
|
+
@value = value
|
6
|
+
end
|
7
|
+
def calculate
|
8
|
+
if curent_unit == 'fahrenheit'
|
9
|
+
@wanted_value = (@value - 32)/1.8
|
10
|
+
elsif curent_unit == 'kelvin'
|
11
|
+
@wanted_value = @value - 273.15
|
12
|
+
else # curent_unit == 'celsius'
|
13
|
+
@wanted_value = @value
|
14
|
+
end
|
15
|
+
return @wanted_value
|
16
|
+
end
|
17
|
+
end
|
data/lib/thermostat.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class Thermostat
|
2
|
+
attr_accessor :wanted_value, :range, :heating, :cooling
|
3
|
+
def initialize(wanted_value = 0, range = 0)
|
4
|
+
@wanted_value = wanted_value
|
5
|
+
@range = range
|
6
|
+
@heating = false
|
7
|
+
@cooling = false
|
8
|
+
end
|
9
|
+
def deviation
|
10
|
+
@deviation = @range/2
|
11
|
+
end
|
12
|
+
def update curent_value
|
13
|
+
if curent_value < @wanted_value - deviation
|
14
|
+
# puts "it is too cold"
|
15
|
+
heating_true
|
16
|
+
elsif curent_value > @wanted_value + deviation
|
17
|
+
# puts "it is too hot"
|
18
|
+
cooling_true
|
19
|
+
else # curent_value == @wanted_value
|
20
|
+
# puts "it is a good temperature"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
def heating_true
|
24
|
+
@heating = true
|
25
|
+
end
|
26
|
+
def cooling_true
|
27
|
+
@cooling = true
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thermostat_drees_camertijn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.C
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Drees Camertijn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: thermostat that receives a json and if it is too cold the heating turns
|
14
|
+
on and if it is too hot the coling turns on
|
15
|
+
email: dreescamertijn@hotmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/json_thermostat.rb
|
21
|
+
- lib/temp_unit.rb
|
22
|
+
- lib/thermostat.rb
|
23
|
+
homepage: http://rubygems.org/gems/hola
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.1
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.0.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: thermostat
|
46
|
+
test_files: []
|