sillevl_temperature_library 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/temp-conv +85 -85
- data/lib/printer/html_printer.rb +15 -0
- data/lib/printer/json_printer.rb +15 -0
- data/lib/printer/text_printer.rb +15 -0
- data/lib/reader/commandline_reader.rb +10 -0
- data/lib/reader/file_reader.rb +10 -0
- data/lib/reader/url_reader.rb +12 -0
- data/lib/sillevl_temperature_library.rb +3 -3
- data/lib/temperature.rb +36 -0
- data/lib/temperature_printer.rb +3 -0
- data/lib/temperature_reader.rb +3 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 548398ba702dff996c40dc3153311d2f00f88879
|
4
|
+
data.tar.gz: ca35496cf4e2a83bd362c0a75295f2422d7b744c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 110e4dcd1d683a408c13a7939f3f6a360fe1de9b98850429c260ad5d43d1bbb316b51190b6002574fbac78db5b18f1a03121bf4b8bcaf2e6b690d4182f569331
|
7
|
+
data.tar.gz: e3dfcd965f141d691f9f87046f285237a1402189c026b33b7d742ac9f007286de7b0b0d6ad0557839aaeeb3eb0c04354f92d0bfb3c3a44eafe9e54097ec51bed
|
data/bin/temp-conv
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'sillevl_temperature_library'
|
4
|
-
require 'highline'
|
5
|
-
require 'optparse'
|
6
|
-
|
7
|
-
|
8
|
-
options = {}
|
9
|
-
OptionParser.new do |opts|
|
10
|
-
opts.banner = "Usage: example.rb [options]"
|
11
|
-
|
12
|
-
opts.on("-i", "--interactive", "Run interactive") do |i|
|
13
|
-
|
14
|
-
cli = HighLine.new
|
15
|
-
cli.choose do |menu|
|
16
|
-
menu.prompt = "Please choose your method of input? "
|
17
|
-
|
18
|
-
menu.choice("CommandLine Interface") do
|
19
|
-
temperature = cli.ask "What is the temperature?"
|
20
|
-
temperature = Temperature.new temperature
|
21
|
-
converter.commandline_temperature temperature
|
22
|
-
cli.say(converter.to_text)
|
23
|
-
end
|
24
|
-
|
25
|
-
menu.choices("From file") do
|
26
|
-
filename = cli.ask "What is the filename?"
|
27
|
-
reader = FileReader.new filename
|
28
|
-
temperature = Temperature.new reader.temperature
|
29
|
-
converter.file_temperature filename
|
30
|
-
cli.say(converter.to_text)
|
31
|
-
end
|
32
|
-
|
33
|
-
menu.choices("From url") do
|
34
|
-
url = cli.ask "What is the url?"
|
35
|
-
reader = UrlReader.new url
|
36
|
-
temperature = Temperature.new reader.temperature
|
37
|
-
converter.url_temperature url
|
38
|
-
cli.say("Not from around here, are you?")
|
39
|
-
end
|
40
|
-
|
41
|
-
menu.choices("Using MQTT") do
|
42
|
-
cli.say("Not from around here, are you?")
|
43
|
-
end
|
44
|
-
|
45
|
-
menu.default = "CommandLine Interface"
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
temperature = Temperature.new 0
|
51
|
-
|
52
|
-
opts.on("-t T", "--temperature T", Float, "Temperature") do |t|
|
53
|
-
temperature = Temperature.new t
|
54
|
-
end
|
55
|
-
|
56
|
-
opts.on("-f FILE", "--file FILE", String, "Temperature") do |file|
|
57
|
-
reader = FileReader.new file
|
58
|
-
temperature = Temperature.new reader.temperature
|
59
|
-
end
|
60
|
-
|
61
|
-
opts.on("-u URL", "--url URL", String, "Temperature") do |url|
|
62
|
-
reader = UrlReader.new url
|
63
|
-
temperature = Temperature.new reader.temperature
|
64
|
-
end
|
65
|
-
|
66
|
-
opts.on("--text", "Output temperature as text") do
|
67
|
-
printer = TextPrinter.new temperature
|
68
|
-
puts printer.print
|
69
|
-
end
|
70
|
-
|
71
|
-
opts.on("--json", "Output temperature as json") do
|
72
|
-
printer = JsonPrinter.new temperature
|
73
|
-
puts printer.print
|
74
|
-
end
|
75
|
-
|
76
|
-
opts.on("--html", "Output temperature as html") do
|
77
|
-
printer = HtmlPrinter.new temperature
|
78
|
-
puts printer.print
|
79
|
-
end
|
80
|
-
|
81
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
82
|
-
puts opts
|
83
|
-
exit
|
84
|
-
end
|
85
|
-
end.parse!
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sillevl_temperature_library'
|
4
|
+
require 'highline'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: example.rb [options]"
|
11
|
+
|
12
|
+
opts.on("-i", "--interactive", "Run interactive") do |i|
|
13
|
+
|
14
|
+
cli = HighLine.new
|
15
|
+
cli.choose do |menu|
|
16
|
+
menu.prompt = "Please choose your method of input? "
|
17
|
+
|
18
|
+
menu.choice("CommandLine Interface") do
|
19
|
+
temperature = cli.ask "What is the temperature?"
|
20
|
+
temperature = Temperature.new temperature
|
21
|
+
converter.commandline_temperature temperature
|
22
|
+
cli.say(converter.to_text)
|
23
|
+
end
|
24
|
+
|
25
|
+
menu.choices("From file") do
|
26
|
+
filename = cli.ask "What is the filename?"
|
27
|
+
reader = FileReader.new filename
|
28
|
+
temperature = Temperature.new reader.temperature
|
29
|
+
converter.file_temperature filename
|
30
|
+
cli.say(converter.to_text)
|
31
|
+
end
|
32
|
+
|
33
|
+
menu.choices("From url") do
|
34
|
+
url = cli.ask "What is the url?"
|
35
|
+
reader = UrlReader.new url
|
36
|
+
temperature = Temperature.new reader.temperature
|
37
|
+
converter.url_temperature url
|
38
|
+
cli.say("Not from around here, are you?")
|
39
|
+
end
|
40
|
+
|
41
|
+
menu.choices("Using MQTT") do
|
42
|
+
cli.say("Not from around here, are you?")
|
43
|
+
end
|
44
|
+
|
45
|
+
menu.default = "CommandLine Interface"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
temperature = Temperature.new 0
|
51
|
+
|
52
|
+
opts.on("-t T", "--temperature T", Float, "Temperature") do |t|
|
53
|
+
temperature = Temperature.new t
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on("-f FILE", "--file FILE", String, "Temperature") do |file|
|
57
|
+
reader = FileReader.new file
|
58
|
+
temperature = Temperature.new reader.temperature
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on("-u URL", "--url URL", String, "Temperature") do |url|
|
62
|
+
reader = UrlReader.new url
|
63
|
+
temperature = Temperature.new reader.temperature
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on("--text", "Output temperature as text") do
|
67
|
+
printer = TextPrinter.new temperature
|
68
|
+
puts printer.print
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on("--json", "Output temperature as json") do
|
72
|
+
printer = JsonPrinter.new temperature
|
73
|
+
puts printer.print
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on("--html", "Output temperature as html") do
|
77
|
+
printer = HtmlPrinter.new temperature
|
78
|
+
puts printer.print
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
82
|
+
puts opts
|
83
|
+
exit
|
84
|
+
end
|
85
|
+
end.parse!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class HtmlPrinter
|
2
|
+
|
3
|
+
def initialize(temperature)
|
4
|
+
@temperature = temperature
|
5
|
+
end
|
6
|
+
|
7
|
+
def print
|
8
|
+
"<div>\r\n"\
|
9
|
+
" <div>#{@temperature.to_celsius} °C</div>\r\n"\
|
10
|
+
" <div>#{@temperature.to_fahrenheit} °F</div>\r\n"\
|
11
|
+
" <div>#{@temperature.to_kelvin} K</div>\r\n"\
|
12
|
+
"</div> "
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class JsonPrinter
|
2
|
+
|
3
|
+
def initialize(temperature)
|
4
|
+
@temperature = temperature
|
5
|
+
end
|
6
|
+
|
7
|
+
def print
|
8
|
+
"{"\
|
9
|
+
"celsius: #{@temperature.to_celsius}, "\
|
10
|
+
"fahrenheit: #{@temperature.to_fahrenheit}, "\
|
11
|
+
"kelvin: #{@temperature.to_kelvin}"\
|
12
|
+
"}"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
class TextPrinter
|
3
|
+
|
4
|
+
def initialize(temperature)
|
5
|
+
@temperature = temperature
|
6
|
+
end
|
7
|
+
|
8
|
+
def print
|
9
|
+
"Temperature:\r\n"\
|
10
|
+
" #{@temperature.to_celsius} °C\r\n"\
|
11
|
+
" #{@temperature.to_fahrenheit} °F\r\n"\
|
12
|
+
" #{@temperature.to_kelvin} K"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
1
|
+
require 'temperature_reader'
|
2
|
+
require 'temperature_printer'
|
3
|
+
require 'temperature'
|
data/lib/temperature.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Temperature type with unit convertion methods
|
2
|
+
#
|
3
|
+
# The Temperature class accepts any temperature value in degrees celsius
|
4
|
+
# and can convert it to any other unit with helper methods
|
5
|
+
# @author Sille Van Landschoot <info@sillevl.be>
|
6
|
+
|
7
|
+
class Temperature
|
8
|
+
|
9
|
+
attr_reader :temperature
|
10
|
+
|
11
|
+
KELVIN_SHIFT = 273.15
|
12
|
+
FAHRENHEIT_OFFSET = 32
|
13
|
+
FAHRENHEIT_SLOPE = Rational(9,5)
|
14
|
+
|
15
|
+
# @param temperature [Number] temperature value in degrees celsius
|
16
|
+
def initialize temperature
|
17
|
+
@temperature = temperature
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return the temperature value in degrees celsius
|
21
|
+
# @return [Number] temperature in degrees celsius
|
22
|
+
# @example
|
23
|
+
# temperature = Temperature.new 12.3
|
24
|
+
# puts temperature.to_celsius
|
25
|
+
def to_celsius
|
26
|
+
temperature
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_fahrenheit
|
30
|
+
(to_celsius * FAHRENHEIT_SLOPE) + FAHRENHEIT_OFFSET
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_kelvin
|
34
|
+
to_celsius + KELVIN_SHIFT
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sillevl_temperature_library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sille Van Landschoot
|
@@ -18,7 +18,16 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- bin/temp-conv
|
21
|
+
- lib/printer/html_printer.rb
|
22
|
+
- lib/printer/json_printer.rb
|
23
|
+
- lib/printer/text_printer.rb
|
24
|
+
- lib/reader/commandline_reader.rb
|
25
|
+
- lib/reader/file_reader.rb
|
26
|
+
- lib/reader/url_reader.rb
|
21
27
|
- lib/sillevl_temperature_library.rb
|
28
|
+
- lib/temperature.rb
|
29
|
+
- lib/temperature_printer.rb
|
30
|
+
- lib/temperature_reader.rb
|
22
31
|
homepage: http://rubygems.org/gems/sillevl_temperature_library
|
23
32
|
licenses:
|
24
33
|
- MIT
|
@@ -39,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
48
|
version: '0'
|
40
49
|
requirements: []
|
41
50
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.5.1
|
51
|
+
rubygems_version: 2.4.5.1
|
43
52
|
signing_key:
|
44
53
|
specification_version: 4
|
45
54
|
summary: Temperature converter library
|