Aython-Houttekier-thermostat-exercise 0.0.0
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 +7 -0
- data/README.md +67 -0
- data/app.rb +36 -0
- data/lib/led.rb +28 -0
- data/lib/thermostat.rb +31 -0
- data/lib/unit.rb +65 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4df78f198a8f52650a16663437ef4574f428058d
|
4
|
+
data.tar.gz: b3224e90e7f0bd7531186a52dee6a8f1b781af25
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c6dd42bfbfbab1d45b15982da0cd27d352fbaa776f4152ba5caa5ad51d622ee8f83ec15042ab0886c60d67cf535051c54f57f42d5d776bebd53e3aae19cc091
|
7
|
+
data.tar.gz: b84bcbb959786956f26da42dab2776262f16573d37185687cdbbd117eb505bcc8d635f73ad0b916a0b3fa8158e52197f61265304f9d7a642983e73559b7445f6
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
## Opdracht 1
|
2
|
+
|
3
|
+
;
|
4
|
+
|
5
|
+
## Opdracht 2
|
6
|
+
|
7
|
+
**0.0.1** -> versie 1 (opdracht 1)
|
8
|
+
|
9
|
+
**0.0.2** -> output led
|
10
|
+
|
11
|
+
te koud => blauw
|
12
|
+
ok => groen
|
13
|
+
te warm => rood
|
14
|
+
|
15
|
+
**0.0.3** -> input unit
|
16
|
+
|
17
|
+
celsius
|
18
|
+
fahrenheit
|
19
|
+
kelvin
|
20
|
+
|
21
|
+
**0.0.4** -> waarden meegeven met commandline
|
22
|
+
ruby app.rb _ _ _ _
|
23
|
+
current wanted range unit
|
24
|
+
|
25
|
+
-> README.md
|
26
|
+
-> Lisence
|
27
|
+
-> GEM
|
28
|
+
|
29
|
+
**0.0.5** -> units
|
30
|
+
inputs met http url
|
31
|
+
|
32
|
+
``currentTemp = URI(https://labict.be/software-engineering/temperature/api/temperature/fake).read``
|
33
|
+
|
34
|
+
outputs met library optparse
|
35
|
+
|
36
|
+
|
37
|
+
### uitvoering app
|
38
|
+
|
39
|
+
om de app op een correcte werkende manier uit te voeren geef je het commando:
|
40
|
+
|
41
|
+
``ruby app.rb 24 20 0.5 C``
|
42
|
+
|
43
|
+
24 -> current value
|
44
|
+
|
45
|
+
20 -> wanted value
|
46
|
+
|
47
|
+
0.5 -> range
|
48
|
+
|
49
|
+
C -> is de unit (je kunt kiezen tussen C,F,K)
|
50
|
+
|
51
|
+
als je een argument vergeten bent dan zal er een melding komen dat het programma exact 4 argumenten nodig heeft.
|
52
|
+
|
53
|
+

|
54
|
+
|
55
|
+
als je andere unit ingeeft dan C,F of K dan zal het programma melden dat deze unit niet bestaat maar het zal wel de waarden die je meegaf weergeven.
|
56
|
+
|
57
|
+

|
58
|
+
|
59
|
+
Wanneer het programma correct wordt uitgevoerd dan krijg je de volgende output
|
60
|
+
|
61
|
+

|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
data/app.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative('lib/thermostat.rb')
|
2
|
+
require_relative('lib/led.rb')
|
3
|
+
require_relative('lib/unit.rb')
|
4
|
+
|
5
|
+
class ThermostatApplication
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
|
9
|
+
thermostat = Thermostat.new(ARGV[0],ARGV[1],ARGV[2])
|
10
|
+
led = Led.new(ARGV[0],ARGV[1],ARGV[2])
|
11
|
+
unit = Unitconverter.new(ARGV[0], ARGV[1], ARGV[2], ARGV[3])
|
12
|
+
|
13
|
+
if ARGV.length != 4
|
14
|
+
puts "We need exactly four arguments"
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "current temp: " + ARGV[0] + "°" + ARGV[3]
|
19
|
+
puts "wanted temp: " + ARGV[1] + "°" + ARGV[3]
|
20
|
+
puts "range: " + ARGV[2] + "°" + ARGV[3]
|
21
|
+
|
22
|
+
|
23
|
+
#cooling and heating true or false
|
24
|
+
puts "cooling: #{thermostat.cooling?}"
|
25
|
+
puts "heating: #{thermostat.heating?}"
|
26
|
+
|
27
|
+
#color of led
|
28
|
+
puts "The led is: #{led.colorled}"
|
29
|
+
|
30
|
+
#unitconverter units
|
31
|
+
puts "#{unit.convertingunit}"
|
32
|
+
end
|
33
|
+
|
34
|
+
ThermostatApplication.new
|
35
|
+
|
36
|
+
end
|
data/lib/led.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative('thermostat.rb')
|
2
|
+
|
3
|
+
class Led
|
4
|
+
|
5
|
+
def initialize (currentValue, wantedValue, range = 0.5)
|
6
|
+
|
7
|
+
@currentValue = currentValue
|
8
|
+
@wantedValue = wantedValue
|
9
|
+
@range = range
|
10
|
+
|
11
|
+
@red = "RGB(255,0,0)"
|
12
|
+
@green = "RGB(0,255,0)"
|
13
|
+
@blue = "RGB(0,0,255)"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def colorled
|
18
|
+
@curAndRange = @currentValue + @range
|
19
|
+
|
20
|
+
if @curAndRange > @wantedValue
|
21
|
+
@red
|
22
|
+
elsif @curAndRange = @wantedValue
|
23
|
+
@blue
|
24
|
+
else
|
25
|
+
@green
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/thermostat.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Thermostat
|
2
|
+
|
3
|
+
|
4
|
+
def initialize (currentValue, wantedValue, range = 0.5)
|
5
|
+
|
6
|
+
@currentValue = currentValue
|
7
|
+
@wantedValue = wantedValue
|
8
|
+
@range = range
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
def current
|
13
|
+
@currentValue
|
14
|
+
end
|
15
|
+
|
16
|
+
def wanted
|
17
|
+
@wantedValue
|
18
|
+
end
|
19
|
+
|
20
|
+
def range
|
21
|
+
@range
|
22
|
+
end
|
23
|
+
|
24
|
+
def heating?
|
25
|
+
@wantedValue > (@currentValue + @range)
|
26
|
+
end
|
27
|
+
|
28
|
+
def cooling?
|
29
|
+
@wantedValue < (@currentValue + @range)
|
30
|
+
end
|
31
|
+
end
|
data/lib/unit.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative('thermostat.rb')
|
2
|
+
|
3
|
+
class Unitconverter
|
4
|
+
|
5
|
+
TOFAHRENHEITFACTOR1 = 1.8
|
6
|
+
TOFAHRENHEITFACTOR2 = 32
|
7
|
+
|
8
|
+
TOKELVIN1 = 273.15
|
9
|
+
TOKELVIN2 = 459.67
|
10
|
+
TOKELVIN3 = 0.55555555
|
11
|
+
|
12
|
+
DECIMALS = 2
|
13
|
+
|
14
|
+
def initialize (currentValue, wantedValue, range = 0.5, unit)
|
15
|
+
|
16
|
+
@currentValue = currentValue.to_i
|
17
|
+
@wantedValue = wantedValue.to_i
|
18
|
+
@range = range.to_i
|
19
|
+
@unit = unit
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def convertingunit
|
24
|
+
if @unit == "C"
|
25
|
+
currentfahrenheit = (@currentValue + @range) * TOFAHRENHEITFACTOR1 + TOFAHRENHEITFACTOR2
|
26
|
+
wantedfahrenheit = @wantedValue * TOFAHRENHEITFACTOR1 + TOFAHRENHEITFACTOR2
|
27
|
+
|
28
|
+
currentkelvin = (@currentValue + @range) + TOKELVIN1
|
29
|
+
wantedkelvin = @wantedValue + TOKELVIN1
|
30
|
+
|
31
|
+
print "Current Temp Fahrenheit = ", currentfahrenheit.round(DECIMALS), " °F", "\n"
|
32
|
+
print "Wanted Temp Fahrenheit = ", wantedfahrenheit.round(DECIMALS), " °F", "\n"
|
33
|
+
print "Current Temp Kelvin = ", currentkelvin.round(DECIMALS), " K", "\n"
|
34
|
+
print "wanted Temp Kelvin = ", wantedkelvin.round(DECIMALS), " K", "\n"
|
35
|
+
|
36
|
+
elsif @unit == "F"
|
37
|
+
currentcelsius = (@currentValue + @range - TOFAHRENHEITFACTOR2) / TOFAHRENHEITFACTOR1
|
38
|
+
wantedcelsius = (@wantedValue - TOFAHRENHEITFACTOR2) / TOFAHRENHEITFACTOR1
|
39
|
+
|
40
|
+
currentkelvin = (@currentValue + @range + TOKELVIN2) * TOKELVIN3
|
41
|
+
wantedkelvin = (@wantedValue + TOKELVIN2) * TOKELVIN3
|
42
|
+
|
43
|
+
print "Current Temp Celsius = ", currentcelsius.round(DECIMALS), " °C", "\n"
|
44
|
+
print "Wanted Temp Celsius = ", wantedcelsius.round(DECIMALS), " °C", "\n"
|
45
|
+
print "Current Temp Kelvin = ", currentkelvin.round(DECIMALS), " K", "\n"
|
46
|
+
print "Wanted Temp Kelvin = ", wantedkelvin.round(DECIMALS), " K", "\n"
|
47
|
+
|
48
|
+
elsif @unit == "K"
|
49
|
+
currentcelsius = @currentValue + @range - TOKELVIN1
|
50
|
+
wantedcelsius = @wantedValue - TOKELVIN1
|
51
|
+
|
52
|
+
curAndRange = @currentValue + @range
|
53
|
+
currentfahrenheit = (curAndRange / TOKELVIN3) - TOKELVIN2
|
54
|
+
wantedfahrenheit = (@wantedValue / TOKELVIN3) - TOKELVIN2
|
55
|
+
|
56
|
+
print "Current Temp Celsius = ", currentcelsius.round(DECIMALS), " °C", "\n"
|
57
|
+
print "Wanted Temp Celsius = ", wantedcelsius.round(DECIMALS), " °C", "\n"
|
58
|
+
print "Current Temp Fahrenheit = ", currentfahrenheit.round(DECIMALS), " °F", "\n"
|
59
|
+
print "Wanted Temp Fahrenheit = ", wantedfahrenheit.round(DECIMALS), " °F", "\n"
|
60
|
+
|
61
|
+
else
|
62
|
+
print "this unit doesn't exist!"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Aython-Houttekier-thermostat-exercise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aython Houttekier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: a ruby gem for a thermostat application
|
14
|
+
email: aython.houttekier@hotmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- app.rb
|
21
|
+
- lib/led.rb
|
22
|
+
- lib/thermostat.rb
|
23
|
+
- lib/unit.rb
|
24
|
+
homepage: https://github.com/svl-softwareengineering-2018/thermostat-aythonhouttekier
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.5.2
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: a thermostat application
|
48
|
+
test_files: []
|