journal-cli 1.0.31 → 1.0.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -17
- data/Rakefile +23 -23
- data/journal-cli.gemspec +8 -8
- data/lib/journal-cli/array.rb +2 -2
- data/lib/journal-cli/checkin.rb +111 -112
- data/lib/journal-cli/color.rb +92 -92
- data/lib/journal-cli/data.rb +1 -1
- data/lib/journal-cli/question.rb +16 -16
- data/lib/journal-cli/section.rb +6 -6
- data/lib/journal-cli/string.rb +5 -5
- data/lib/journal-cli/version.rb +1 -1
- data/lib/journal-cli/weather.rb +38 -38
- data/lib/journal-cli.rb +37 -37
- data/src/_README.md +5 -7
- metadata +3 -2
data/lib/journal-cli/color.rb
CHANGED
@@ -17,67 +17,67 @@ module Color
|
|
17
17
|
# @example Send a text string as a color
|
18
18
|
# Color.send('red') => "\e[31m"
|
19
19
|
ATTRIBUTES = [
|
20
|
-
[:clear,
|
21
|
-
[:reset,
|
22
|
-
[:bold,
|
23
|
-
[:dark,
|
24
|
-
[:italic,
|
25
|
-
[:underline,
|
26
|
-
[:underscore,
|
27
|
-
[:blink,
|
28
|
-
[:rapid_blink,
|
29
|
-
[:negative,
|
30
|
-
[:concealed,
|
31
|
-
[:strikethrough,
|
32
|
-
[:strike,
|
33
|
-
[:black,
|
34
|
-
[:red,
|
35
|
-
[:green,
|
36
|
-
[:yellow,
|
37
|
-
[:blue,
|
38
|
-
[:magenta,
|
39
|
-
[:purple,
|
40
|
-
[:cyan,
|
41
|
-
[:white,
|
42
|
-
[:bgblack,
|
43
|
-
[:bgred,
|
44
|
-
[:bggreen,
|
45
|
-
[:bgyellow,
|
46
|
-
[:bgblue,
|
47
|
-
[:bgmagenta,
|
48
|
-
[:bgpurple,
|
49
|
-
[:bgcyan,
|
50
|
-
[:bgwhite,
|
51
|
-
[:boldblack,
|
52
|
-
[:boldred,
|
53
|
-
[:boldgreen,
|
54
|
-
[:boldyellow,
|
55
|
-
[:boldblue,
|
56
|
-
[:boldmagenta,
|
57
|
-
[:boldpurple,
|
58
|
-
[:boldcyan,
|
59
|
-
[:boldwhite,
|
60
|
-
[:boldbgblack,
|
61
|
-
[:boldbgred,
|
62
|
-
[:boldbggreen,
|
63
|
-
[:boldbgyellow,
|
64
|
-
[:boldbgblue,
|
65
|
-
[:boldbgmagenta,
|
66
|
-
[:boldbgpurple,
|
67
|
-
[:boldbgcyan,
|
68
|
-
[:boldbgwhite,
|
69
|
-
[:softpurple,
|
70
|
-
[:hotpants,
|
71
|
-
[:knightrider,
|
72
|
-
[:flamingo,
|
73
|
-
[:yeller,
|
74
|
-
[:whiteboard,
|
75
|
-
[:chalkboard,
|
76
|
-
[:led,
|
77
|
-
[:redacted,
|
78
|
-
[:alert,
|
79
|
-
[:error,
|
80
|
-
[:default,
|
20
|
+
[:clear, 0], # String#clear is already used to empty string in Ruby 1.9
|
21
|
+
[:reset, 0], # synonym for :clear
|
22
|
+
[:bold, 1],
|
23
|
+
[:dark, 2],
|
24
|
+
[:italic, 3], # not widely implemented
|
25
|
+
[:underline, 4],
|
26
|
+
[:underscore, 4], # synonym for :underline
|
27
|
+
[:blink, 5],
|
28
|
+
[:rapid_blink, 6], # not widely implemented
|
29
|
+
[:negative, 7], # no reverse because of String#reverse
|
30
|
+
[:concealed, 8],
|
31
|
+
[:strikethrough, 9], # not widely implemented
|
32
|
+
[:strike, 9], # not widely implemented
|
33
|
+
[:black, 30],
|
34
|
+
[:red, 31],
|
35
|
+
[:green, 32],
|
36
|
+
[:yellow, 33],
|
37
|
+
[:blue, 34],
|
38
|
+
[:magenta, 35],
|
39
|
+
[:purple, 35],
|
40
|
+
[:cyan, 36],
|
41
|
+
[:white, 37],
|
42
|
+
[:bgblack, 40],
|
43
|
+
[:bgred, 41],
|
44
|
+
[:bggreen, 42],
|
45
|
+
[:bgyellow, 43],
|
46
|
+
[:bgblue, 44],
|
47
|
+
[:bgmagenta, 45],
|
48
|
+
[:bgpurple, 45],
|
49
|
+
[:bgcyan, 46],
|
50
|
+
[:bgwhite, 47],
|
51
|
+
[:boldblack, 90],
|
52
|
+
[:boldred, 91],
|
53
|
+
[:boldgreen, 92],
|
54
|
+
[:boldyellow, 93],
|
55
|
+
[:boldblue, 94],
|
56
|
+
[:boldmagenta, 95],
|
57
|
+
[:boldpurple, 95],
|
58
|
+
[:boldcyan, 96],
|
59
|
+
[:boldwhite, 97],
|
60
|
+
[:boldbgblack, 100],
|
61
|
+
[:boldbgred, 101],
|
62
|
+
[:boldbggreen, 102],
|
63
|
+
[:boldbgyellow, 103],
|
64
|
+
[:boldbgblue, 104],
|
65
|
+
[:boldbgmagenta, 105],
|
66
|
+
[:boldbgpurple, 105],
|
67
|
+
[:boldbgcyan, 106],
|
68
|
+
[:boldbgwhite, 107],
|
69
|
+
[:softpurple, "0;35;40"],
|
70
|
+
[:hotpants, "7;34;40"],
|
71
|
+
[:knightrider, "7;30;40"],
|
72
|
+
[:flamingo, "7;31;47"],
|
73
|
+
[:yeller, "1;37;43"],
|
74
|
+
[:whiteboard, "1;30;47"],
|
75
|
+
[:chalkboard, "1;37;40"],
|
76
|
+
[:led, "0;32;40"],
|
77
|
+
[:redacted, "0;30;40"],
|
78
|
+
[:alert, "1;31;43"],
|
79
|
+
[:error, "1;37;41"],
|
80
|
+
[:default, "0;39"]
|
81
81
|
].map(&:freeze).freeze
|
82
82
|
|
83
83
|
# Array of attribute keys only
|
@@ -109,8 +109,8 @@ module Color
|
|
109
109
|
##
|
110
110
|
def validate_color
|
111
111
|
valid_color = nil
|
112
|
-
compiled =
|
113
|
-
normalize_color.
|
112
|
+
compiled = ""
|
113
|
+
normalize_color.chars.each do |char|
|
114
114
|
compiled += char
|
115
115
|
valid_color = compiled if Color.attributes.include?(compiled.to_sym) || compiled =~ /^([fb]g?)?#([a-f0-9]{6})$/i
|
116
116
|
end
|
@@ -126,7 +126,7 @@ module Color
|
|
126
126
|
## @return [String] Normalized color name
|
127
127
|
##
|
128
128
|
def normalize_color
|
129
|
-
|
129
|
+
delete("_").sub(/bright/i, "bold").sub(/bgbold/, "boldbg")
|
130
130
|
end
|
131
131
|
|
132
132
|
# Get the calculated ANSI color at the end of the
|
@@ -137,7 +137,7 @@ module Color
|
|
137
137
|
def last_color_code
|
138
138
|
m = scan(ESCAPE_REGEX)
|
139
139
|
|
140
|
-
em = [
|
140
|
+
em = ["0"]
|
141
141
|
fg = nil
|
142
142
|
bg = nil
|
143
143
|
rgbf = nil
|
@@ -145,8 +145,8 @@ module Color
|
|
145
145
|
|
146
146
|
m.each do |c|
|
147
147
|
case c
|
148
|
-
when
|
149
|
-
em = [
|
148
|
+
when "0"
|
149
|
+
em = ["0"]
|
150
150
|
fg, bg, rgbf, rgbb = nil
|
151
151
|
when /^[34]8/
|
152
152
|
case c
|
@@ -158,7 +158,7 @@ module Color
|
|
158
158
|
rgbb = c
|
159
159
|
end
|
160
160
|
else
|
161
|
-
c.split(
|
161
|
+
c.split(";").each do |i|
|
162
162
|
x = i.to_i
|
163
163
|
if x <= 9
|
164
164
|
em << x
|
@@ -179,10 +179,10 @@ module Color
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
escape = "\e[#{em.join(
|
182
|
+
escape = "\e[#{em.join(";")}m"
|
183
183
|
escape += "\e[#{rgbb}m" if rgbb
|
184
184
|
escape += "\e[#{rgbf}m" if rgbf
|
185
|
-
escape + "\e[#{[fg, bg].delete_if(&:nil?).join(
|
185
|
+
escape + "\e[#{[fg, bg].delete_if(&:nil?).join(";")}m"
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -230,24 +230,24 @@ module Color
|
|
230
230
|
## @return [String] Colorized string
|
231
231
|
##
|
232
232
|
def template(input)
|
233
|
-
input = input.join(
|
234
|
-
return input.gsub(/(?<!\\)\{(\w+)\}/i,
|
233
|
+
input = input.join(" ") if input.is_a? Array
|
234
|
+
return input.gsub(/(?<!\\)\{(\w+)\}/i, "") unless Color.coloring?
|
235
235
|
|
236
236
|
input = input.gsub(/(?<!\\)\{((?:[fb]g?)?#[a-f0-9]{3,6})\}/i) do
|
237
|
-
|
238
|
-
|
239
|
-
|
237
|
+
hex = Regexp.last_match(1)
|
238
|
+
rgb(hex)
|
239
|
+
end
|
240
240
|
|
241
|
-
fmt = input.gsub(/%/,
|
241
|
+
fmt = input.gsub(/%/, "%%")
|
242
242
|
fmt = fmt.gsub(/(?<!\\)\{(\w+)\}/i) do
|
243
|
-
Regexp.last_match(1).
|
243
|
+
Regexp.last_match(1).chars.map { |c| "%<#{c}>s" }.join("")
|
244
244
|
end
|
245
245
|
|
246
|
-
colors = {
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
246
|
+
colors = {w: white, k: black, g: green, l: blue,
|
247
|
+
y: yellow, c: cyan, m: magenta, r: red,
|
248
|
+
W: bgwhite, K: bgblack, G: bggreen, L: bgblue,
|
249
|
+
Y: bgyellow, C: bgcyan, M: bgmagenta, R: bgred,
|
250
|
+
d: dark, b: bold, u: underline, i: italic, x: reset}
|
251
251
|
|
252
252
|
format(fmt, colors)
|
253
253
|
end
|
@@ -275,12 +275,12 @@ module Color
|
|
275
275
|
|
276
276
|
module_eval(new_method)
|
277
277
|
|
278
|
-
next unless
|
278
|
+
next unless /bold/.match?(c)
|
279
279
|
|
280
280
|
# Accept brightwhite in addition to boldwhite
|
281
281
|
new_method = <<-EOSCRIPT
|
282
282
|
# color string as #{c}
|
283
|
-
def #{c.to_s.sub(/bold/,
|
283
|
+
def #{c.to_s.sub(/bold/, "bright")}(string = nil)
|
284
284
|
result = ''
|
285
285
|
result << "\e[#{v}m" if Color.coloring?
|
286
286
|
if block_given?
|
@@ -308,8 +308,8 @@ module Color
|
|
308
308
|
## @return [String] ANSI escape string
|
309
309
|
##
|
310
310
|
def rgb(hex)
|
311
|
-
is_bg =
|
312
|
-
hex_string = hex.sub(/^([fb]g?)?#/,
|
311
|
+
is_bg = /^bg?#/.match?(hex)
|
312
|
+
hex_string = hex.sub(/^([fb]g?)?#/, "")
|
313
313
|
|
314
314
|
if hex_string.length == 3
|
315
315
|
parts = hex_string.match(/(?<r>.)(?<g>.)(?<b>.)/)
|
@@ -319,7 +319,7 @@ module Color
|
|
319
319
|
t << parts[e]
|
320
320
|
t << parts[e]
|
321
321
|
end
|
322
|
-
hex_string = t.join(
|
322
|
+
hex_string = t.join("")
|
323
323
|
end
|
324
324
|
|
325
325
|
parts = hex_string.match(/(?<r>..)(?<g>..)(?<b>..)/)
|
@@ -328,7 +328,7 @@ module Color
|
|
328
328
|
t << parts[e].hex
|
329
329
|
end
|
330
330
|
|
331
|
-
"\e[#{is_bg ?
|
331
|
+
"\e[#{is_bg ? "48" : "38"};2;#{t.join(";")}m"
|
332
332
|
end
|
333
333
|
|
334
334
|
# Regular expression that is used to scan for ANSI-sequences while
|
@@ -339,13 +339,13 @@ module Color
|
|
339
339
|
# ANSI-sequences are stripped from the string.
|
340
340
|
def uncolor(string = nil) # :yields:
|
341
341
|
if block_given?
|
342
|
-
yield.to_str.gsub(COLORED_REGEXP,
|
342
|
+
yield.to_str.gsub(COLORED_REGEXP, "")
|
343
343
|
elsif string.respond_to?(:to_str)
|
344
|
-
string.to_str.gsub(COLORED_REGEXP,
|
344
|
+
string.to_str.gsub(COLORED_REGEXP, "")
|
345
345
|
elsif respond_to?(:to_str)
|
346
|
-
to_str.gsub(COLORED_REGEXP,
|
346
|
+
to_str.gsub(COLORED_REGEXP, "")
|
347
347
|
else
|
348
|
-
|
348
|
+
""
|
349
349
|
end
|
350
350
|
end
|
351
351
|
|
data/lib/journal-cli/data.rb
CHANGED
data/lib/journal-cli/question.rb
CHANGED
@@ -13,14 +13,14 @@ module Journal
|
|
13
13
|
## @return [Question] the question object
|
14
14
|
##
|
15
15
|
def initialize(question)
|
16
|
-
@key = question[
|
17
|
-
@type = question[
|
18
|
-
@min = question[
|
19
|
-
@max = question[
|
20
|
-
@prompt = question[
|
21
|
-
@secondary_prompt = question[
|
22
|
-
@gum = TTY::Which.exist?(
|
23
|
-
@condition = question.key?(
|
16
|
+
@key = question["key"]
|
17
|
+
@type = question["type"]
|
18
|
+
@min = question["min"]&.to_i || 1
|
19
|
+
@max = question["max"]&.to_i || 5
|
20
|
+
@prompt = question["prompt"] || nil
|
21
|
+
@secondary_prompt = question["secondary_prompt"] || nil
|
22
|
+
@gum = TTY::Which.exist?("gum")
|
23
|
+
@condition = question.key?("condition") ? question["condition"].parse_condition : true
|
24
24
|
end
|
25
25
|
|
26
26
|
##
|
@@ -41,7 +41,7 @@ module Journal
|
|
41
41
|
when /^(text|string|line)/i
|
42
42
|
read_line
|
43
43
|
when /^(weather|forecast)/i
|
44
|
-
Weather.new(Journal.config[
|
44
|
+
Weather.new(Journal.config["weather_api"], Journal.config["zip"], Journal.config["temp_in"])
|
45
45
|
when /^multi/i
|
46
46
|
read_lines
|
47
47
|
when /^(date|time)/i
|
@@ -92,7 +92,7 @@ module Journal
|
|
92
92
|
Journal.notify("{by}#{prompt}")
|
93
93
|
|
94
94
|
line = @gum ? read_line_gum(prompt) : read_line_tty
|
95
|
-
return output.join("\n") if
|
95
|
+
return output.join("\n") if /^ *$/.match?(line)
|
96
96
|
|
97
97
|
output << line
|
98
98
|
output << read_line(prompt: @secondary_prompt) unless @secondary_prompt.nil?
|
@@ -129,7 +129,7 @@ module Journal
|
|
129
129
|
##
|
130
130
|
##
|
131
131
|
def read_number_gum
|
132
|
-
trap(
|
132
|
+
trap("SIGINT") { exit! }
|
133
133
|
res = `gum input --placeholder "#{@min}-#{@max}"`.strip
|
134
134
|
return nil if res.strip.empty?
|
135
135
|
|
@@ -144,9 +144,9 @@ module Journal
|
|
144
144
|
## @return [Number] integer response
|
145
145
|
##
|
146
146
|
def read_line_tty
|
147
|
-
trap(
|
147
|
+
trap("SIGINT") { exit! }
|
148
148
|
reader = TTY::Reader.new
|
149
|
-
res = reader.read_line(
|
149
|
+
res = reader.read_line(">> ")
|
150
150
|
return nil if res.strip.empty?
|
151
151
|
|
152
152
|
res
|
@@ -160,7 +160,7 @@ module Journal
|
|
160
160
|
## @return [Number] integer response
|
161
161
|
##
|
162
162
|
def read_line_gum(prompt)
|
163
|
-
trap(
|
163
|
+
trap("SIGINT") { exit! }
|
164
164
|
`gum input --placeholder "#{prompt} (blank to end answer)"`
|
165
165
|
end
|
166
166
|
|
@@ -170,7 +170,7 @@ module Journal
|
|
170
170
|
## @return [string] multiline input
|
171
171
|
##
|
172
172
|
def read_mutliline_tty
|
173
|
-
trap(
|
173
|
+
trap("SIGINT") { exit! }
|
174
174
|
reader = TTY::Reader.new
|
175
175
|
res = reader.read_multiline
|
176
176
|
res.join("\n")
|
@@ -182,7 +182,7 @@ module Journal
|
|
182
182
|
## @return [string] multiline input
|
183
183
|
##
|
184
184
|
def read_multiline_gum(prompt)
|
185
|
-
trap(
|
185
|
+
trap("SIGINT") { exit! }
|
186
186
|
`gum write --placeholder "#{prompt}" --width 80 --char-limit 0`
|
187
187
|
end
|
188
188
|
end
|
data/lib/journal-cli/section.rb
CHANGED
@@ -13,10 +13,10 @@ module Journal
|
|
13
13
|
## @return [Section] the configured section
|
14
14
|
##
|
15
15
|
def initialize(section)
|
16
|
-
@key = section[
|
17
|
-
@title = section[
|
18
|
-
@condition = section.key?(
|
19
|
-
@questions = section[
|
16
|
+
@key = section["key"]
|
17
|
+
@title = section["title"]
|
18
|
+
@condition = section.key?("condition") ? section["condition"].parse_condition : true
|
19
|
+
@questions = section["questions"].map { |question| Question.new(question) }
|
20
20
|
@questions.delete_if { |q| q.prompt.nil? }
|
21
21
|
@answers = {}
|
22
22
|
ask_questions
|
@@ -29,9 +29,9 @@ module Journal
|
|
29
29
|
##
|
30
30
|
def ask_questions
|
31
31
|
@questions.each do |question|
|
32
|
-
if question.key
|
32
|
+
if /\./.match?(question.key)
|
33
33
|
res = @answers
|
34
|
-
keys = question.key.split(
|
34
|
+
keys = question.key.split(".")
|
35
35
|
keys.each_with_index do |key, i|
|
36
36
|
next if i == keys.count - 1
|
37
37
|
|
data/lib/journal-cli/string.rb
CHANGED
@@ -5,17 +5,17 @@ class ::String
|
|
5
5
|
def parse_condition
|
6
6
|
condition = dup
|
7
7
|
time_rx = /(?<comp>[<>=]{1,2}|before|after) +(?<time>(?:noon|midnight|[0-9]+) *(?:am|pm)?)$/i
|
8
|
-
return true unless condition
|
8
|
+
return true unless condition&.match?(time_rx)
|
9
9
|
|
10
10
|
now = Journal.date
|
11
11
|
m = condition.match(time_rx)
|
12
|
-
time = Chronic.parse(m[
|
12
|
+
time = Chronic.parse(m["time"])
|
13
13
|
now.localtime
|
14
14
|
time.localtime
|
15
|
-
time_of_day = Time.parse("#{now.strftime(
|
16
|
-
Journal.notify("{br}Invalid time string in question (#{m[
|
15
|
+
time_of_day = Time.parse("#{now.strftime("%Y-%m-%d")} #{time.strftime("%H:%M")}")
|
16
|
+
Journal.notify("{br}Invalid time string in question (#{m["time"]})", exit_code: 4) unless time
|
17
17
|
|
18
|
-
case m[
|
18
|
+
case m["comp"]
|
19
19
|
when /^<=$/
|
20
20
|
now <= time_of_day
|
21
21
|
when /^(<|bef)/i
|
data/lib/journal-cli/version.rb
CHANGED
data/lib/journal-cli/weather.rb
CHANGED
@@ -6,50 +6,50 @@ module Journal
|
|
6
6
|
|
7
7
|
def initialize(api, zip, temp_in)
|
8
8
|
Journal.date.localtime
|
9
|
-
if Journal.date.strftime(
|
10
|
-
|
9
|
+
res = if Journal.date.strftime("%Y-%m-%d") == Time.now.strftime("%Y-%m-%d")
|
10
|
+
`curl -SsL 'http://api.weatherapi.com/v1/forecast.json?key=#{api}&q=#{zip}&aqi=no'`
|
11
11
|
else
|
12
|
-
|
12
|
+
`curl -SsL 'http://api.weatherapi.com/v1/history.json?key=#{api}&q=#{zip}&aqi=no&dt=#{Journal.date.strftime("%Y-%m-%d")}'`
|
13
13
|
end
|
14
14
|
|
15
15
|
data = JSON.parse(res)
|
16
16
|
|
17
|
-
raise StandardError,
|
17
|
+
raise StandardError, "invalid JSON response" if data.nil?
|
18
18
|
|
19
|
-
raise StandardError,
|
19
|
+
raise StandardError, "missing forecast" unless data["forecast"]
|
20
20
|
|
21
|
-
temp_key =
|
21
|
+
temp_key = /^c/.match?(temp_in) ? "temp_c" : "temp_f"
|
22
22
|
|
23
|
-
if Journal.date.strftime(
|
24
|
-
raise StandardError,
|
23
|
+
if Journal.date.strftime("%Y-%m-%d") == Time.now.strftime("%Y-%m-%d")
|
24
|
+
raise StandardError, "missing conditions" unless data["current"]
|
25
25
|
|
26
|
-
curr_temp = data[
|
27
|
-
curr_condition = data[
|
26
|
+
curr_temp = data["current"][temp_key]
|
27
|
+
curr_condition = data["current"]["condition"]["text"]
|
28
28
|
else
|
29
|
-
time = Journal.date.strftime(
|
30
|
-
hour = data[
|
29
|
+
time = Journal.date.strftime("%Y-%m-%d %H:00")
|
30
|
+
hour = data["forecast"]["forecastday"][0]["hour"].find { |h| h["time"].to_s =~ /#{time}/ }
|
31
31
|
curr_temp = hour[temp_key]
|
32
|
-
curr_condition = hour[
|
32
|
+
curr_condition = hour["condition"]["text"]
|
33
33
|
end
|
34
34
|
|
35
|
-
forecast = data[
|
35
|
+
forecast = data["forecast"]["forecastday"][0]
|
36
36
|
|
37
|
-
moon_phase = forecast[
|
37
|
+
moon_phase = forecast["astro"]["moon_phase"]
|
38
38
|
|
39
|
-
day = forecast[
|
40
|
-
high =
|
41
|
-
low =
|
42
|
-
condition = forecast[
|
39
|
+
day = forecast["date"]
|
40
|
+
high = /^c/.match?(temp_in) ? forecast["day"]["maxtemp_c"] : forecast["day"]["maxtemp_f"]
|
41
|
+
low = /^c/.match?(temp_in) ? forecast["day"]["mintemp_c"] : forecast["day"]["mintemp_f"]
|
42
|
+
condition = forecast["day"]["condition"]["text"]
|
43
43
|
|
44
|
-
hours = forecast[
|
44
|
+
hours = forecast["hour"]
|
45
45
|
temps = [
|
46
|
-
{
|
47
|
-
{
|
48
|
-
{
|
49
|
-
{
|
50
|
-
{
|
51
|
-
{
|
52
|
-
{
|
46
|
+
{temp: hours[8][temp_key], condition: hours[8]["condition"]["text"]},
|
47
|
+
{temp: hours[10][temp_key], condition: hours[10]["condition"]["text"]},
|
48
|
+
{temp: hours[12][temp_key], condition: hours[12]["condition"]["text"]},
|
49
|
+
{temp: hours[14][temp_key], condition: hours[14]["condition"]["text"]},
|
50
|
+
{temp: hours[16][temp_key], condition: hours[16]["condition"]["text"]},
|
51
|
+
{temp: hours[18][temp_key], condition: hours[18]["condition"]["text"]},
|
52
|
+
{temp: hours[19][temp_key], condition: hours[20]["condition"]["text"]}
|
53
53
|
]
|
54
54
|
|
55
55
|
@data = {
|
@@ -95,43 +95,43 @@ module Journal
|
|
95
95
|
output << "Forecast for #{@data[:day]}: #{forecast} "
|
96
96
|
output << "Currently: #{current} "
|
97
97
|
output << "Moon Phase: #{moon} "
|
98
|
-
output <<
|
98
|
+
output << ""
|
99
99
|
|
100
100
|
# Hours
|
101
101
|
hours_text = %w[8am 10am 12pm 2pm 4pm 6pm 8pm]
|
102
|
-
step_out = [
|
102
|
+
step_out = ["|"]
|
103
103
|
@data[:temps].each_with_index do |_h, i|
|
104
104
|
width = @data[:temps][i][:condition].length + 1
|
105
105
|
step_out << format("%#{width}s |", hours_text[i])
|
106
106
|
end
|
107
107
|
|
108
|
-
output << step_out.join(
|
108
|
+
output << step_out.join("")
|
109
109
|
|
110
110
|
# table separator
|
111
|
-
step_out = [
|
111
|
+
step_out = ["|"]
|
112
112
|
@data[:temps].each do |temp|
|
113
113
|
width = temp[:condition].length + 1
|
114
|
-
step_out << "#{
|
114
|
+
step_out << "#{"-" * width}-|"
|
115
115
|
end
|
116
116
|
|
117
|
-
output << step_out.join(
|
117
|
+
output << step_out.join("")
|
118
118
|
|
119
119
|
# Conditions
|
120
|
-
step_out = [
|
120
|
+
step_out = ["|"]
|
121
121
|
@data[:temps].each do |temp|
|
122
|
-
step_out << format(
|
122
|
+
step_out << format(" %s |", temp[:condition])
|
123
123
|
end
|
124
124
|
|
125
|
-
output << step_out.join(
|
125
|
+
output << step_out.join("")
|
126
126
|
|
127
127
|
# Temps
|
128
|
-
step_out = [
|
128
|
+
step_out = ["|"]
|
129
129
|
@data[:temps].each do |temp|
|
130
130
|
width = temp[:condition].length + 1
|
131
131
|
step_out << format("%#{width}s |", temp[:temp])
|
132
132
|
end
|
133
133
|
|
134
|
-
output << step_out.join(
|
134
|
+
output << step_out.join("")
|
135
135
|
|
136
136
|
output.join("\n")
|
137
137
|
end
|