Lenny-Vanderlinden-thermostat-exercise-2 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/app +58 -0
- data/lib/Thermostat.rb +43 -0
- data/lib/convert.rb +29 -0
- data/lib/jsonConvertor.rb +10 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c920d68a6937a70ba16cb50c136c8c653cfa51c
|
4
|
+
data.tar.gz: 4ddd1616bb741a5a9d52870854c1a9cc7578d051
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f33d4fa60843e27582c94e5ccbc9ad0b62ce1b8b724e824bfbd1bb3415bd0e352caf1da0d7854fa6c05c42fecaf355bd88e9527a63274336a4bf77a5067b874f
|
7
|
+
data.tar.gz: 25e28d0b96979e82fd89eb2b3e9bc57ac71f11235f3362f6deedb6d6a34adc18c8a507df2e747c97303e9720d714fb4a6c38bda6d22bfe74aab2db5557f21325
|
data/bin/app
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "./lib/Thermostat.rb"
|
2
|
+
require "./lib/convert.rb"
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
# foo.clitemp(ARGV[0].to_i,ARGV[1].to_i,ARGV[2].to_i)
|
6
|
+
|
7
|
+
|
8
|
+
options = {:wantedTemp => nil, :currentTemp => nil, :range => nil}
|
9
|
+
parser = OptionParser.new do |opts|
|
10
|
+
|
11
|
+
opts.banner = "Usage: .rb [options]"
|
12
|
+
|
13
|
+
opts.on('-r', '--range R',Float, 'Range') do |range|
|
14
|
+
options[:range] = range;
|
15
|
+
@range= range
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-w', '--Wanted Temperature',Float, 'Wanted Temperature') do |wantedTemp|
|
19
|
+
options[:wantedTemp] = wantedTemp;
|
20
|
+
@wantedTemp = wantedTemp
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-c', '--celcius C',Float, 'Celcius') do |currentTemp|
|
24
|
+
options[:currentTemp] = currentTemp;
|
25
|
+
@currentTemp = currentTemp
|
26
|
+
@unit = "c"
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-k', '--kelvin K', Float , 'Kelvin') do |currentTemp|
|
30
|
+
options[:currentTemp] = currentTemp;
|
31
|
+
@currentTemp = currentTemp
|
32
|
+
@unit = "k"
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on('-f', '--fahrenheit F', Float, 'Fahrenheit') do |currentTemp|
|
36
|
+
options[:currentTemp] = currentTemp;
|
37
|
+
@currentTemp = currentTemp
|
38
|
+
@unit = "f"
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on_tail("-h", "--help", "Example usage: ruby app.rb -r 1 -w 20 -c 22") do
|
42
|
+
puts opts
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
parser.parse!
|
49
|
+
|
50
|
+
puts "range: #{@range}"
|
51
|
+
puts "current: #{@currentTemp}"
|
52
|
+
puts "wanted: #{@wantedTemp}"
|
53
|
+
puts "unit: #{@unit}"
|
54
|
+
|
55
|
+
foo = Thermostat.new(@currentTemp,@range,@wantedTemp,@unit)
|
56
|
+
foo.regulate()
|
57
|
+
foo.output()
|
58
|
+
foo.outputJson()
|
data/lib/Thermostat.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
require "./lib/convert.rb"
|
3
|
+
class Thermostat
|
4
|
+
def initialize(currentTemp,range,wantedTemp,unit)
|
5
|
+
@currentTemp = currentTemp
|
6
|
+
@wantedTemp = wantedTemp
|
7
|
+
@range = range
|
8
|
+
@unit = unit
|
9
|
+
@heater = false
|
10
|
+
@airco = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def regulate()
|
14
|
+
c = Convert.new(@currentTemp,@range,@wantedTemp,@unit)
|
15
|
+
c.convert_temp()
|
16
|
+
if c.endtemp > (c.endWantedTemp + c.endrange)
|
17
|
+
@airco = true
|
18
|
+
@heater = false
|
19
|
+
elsif c.endtemp < (c.endWantedTemp - c.endrange)
|
20
|
+
@airco = false
|
21
|
+
@heater = true
|
22
|
+
else
|
23
|
+
@airco = false
|
24
|
+
@heater = false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def output()
|
29
|
+
if(@airco == false && @heater == false)
|
30
|
+
puts "The current temperature is equal to the wanted temperature"
|
31
|
+
elsif (@airco == false && @heater == true)
|
32
|
+
puts "The heater is on, the Airco is off"
|
33
|
+
elsif (@airco == true && @heater == false)
|
34
|
+
puts "The heater is off, the Airco is on"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def outputJson()
|
39
|
+
my_object = { :heater => @heater, :airco => @airco }
|
40
|
+
@outputJson = JSON.pretty_generate(my_object)
|
41
|
+
puts @outputJson
|
42
|
+
end
|
43
|
+
end
|
data/lib/convert.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "./lib/Thermostat.rb"
|
2
|
+
class Convert
|
3
|
+
attr_reader :endtemp, :endrange, :endWantedTemp
|
4
|
+
|
5
|
+
def initialize(currentTemp,range,wantedTemp,unit)
|
6
|
+
@currentTemp = currentTemp
|
7
|
+
@range = range
|
8
|
+
@wantedTemp = wantedTemp
|
9
|
+
@unit = unit
|
10
|
+
end
|
11
|
+
|
12
|
+
def convert_temp()
|
13
|
+
if (@unit == "f")
|
14
|
+
@endtemp = @currentTemp * 1.8 + 32
|
15
|
+
@endrange = @range * 1.8
|
16
|
+
@endWantedTemp = @wantedTemp * 1.8 + 32
|
17
|
+
elsif (@unit == "k")
|
18
|
+
@endtemp = @currentTemp + 273.15
|
19
|
+
@endrange = @range * 2.7
|
20
|
+
@endWantedTemp = @wantedTemp + 273.15
|
21
|
+
elsif (@unit =="c")
|
22
|
+
@endtemp = @currentTemp
|
23
|
+
@endrange = @range
|
24
|
+
@endWantedTemp = @wantedTemp
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Lenny-Vanderlinden-thermostat-exercise-2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lenny Vanderlinden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: App to change the temperature/thermostat to your liking by input
|
14
|
+
email: lenny.vanderlinden@student.vives.be
|
15
|
+
executables:
|
16
|
+
- app
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/app
|
21
|
+
- lib/Thermostat.rb
|
22
|
+
- lib/convert.rb
|
23
|
+
- lib/jsonConvertor.rb
|
24
|
+
homepage: https://github.com/svl-softwareengineering-2018/thermostat-lennyvdl
|
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.6.12
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: thermostaat
|
48
|
+
test_files: []
|