weatherGem 0.1.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/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/environment.rb +18 -0
- data/config/settings +7 -0
- data/lib/concerns/menus.rb +56 -0
- data/lib/concerns/modules.rb +12 -0
- data/lib/concerns/return_html.rb +15 -0
- data/lib/concerns/weathercard.rb +27 -0
- data/lib/forecast.rb +11 -0
- data/lib/gather_data.rb +38 -0
- data/lib/parse_data.rb +345 -0
- data/lib/run.rb +11 -0
- data/lib/settings.rb +42 -0
- data/lib/weatherCLI.rb +46 -0
- data/lib/weatherCLI/version.rb +3 -0
- data/lib/weathercard.rb +364 -0
- metadata +130 -0
data/lib/run.rb
ADDED
data/lib/settings.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
class Settings
|
|
2
|
+
attr_accessor :zip_codes
|
|
3
|
+
|
|
4
|
+
@@zip_codes = []
|
|
5
|
+
|
|
6
|
+
def self.init
|
|
7
|
+
if !File.file?(SETTINGS_PATH)
|
|
8
|
+
self.save_zips
|
|
9
|
+
end
|
|
10
|
+
file = File.read(SETTINGS_PATH)
|
|
11
|
+
settings_hash = JSON.parse(file)
|
|
12
|
+
@@zip_codes = settings_hash["zip_codes"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.class_hash
|
|
16
|
+
{"zip_codes" => @@zip_codes}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.zip_codes
|
|
20
|
+
@@zip_codes
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.reset_zips
|
|
24
|
+
@@zip_code = []
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.save
|
|
28
|
+
File.open(SETTINGS_PATH, 'w') do |f|
|
|
29
|
+
f.write(JSON.pretty_generate(self.class_hash))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.add_zip(zip)
|
|
34
|
+
@@zip_codes << zip
|
|
35
|
+
self.save
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.remove_zip(zip)
|
|
39
|
+
@@zip_codes.delete(zip)
|
|
40
|
+
self.save
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/weatherCLI.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "./config/environment"
|
|
2
|
+
|
|
3
|
+
module WeatherCLI
|
|
4
|
+
# Your code goes here...
|
|
5
|
+
class SingleDay
|
|
6
|
+
|
|
7
|
+
def self.display(zip='72703')
|
|
8
|
+
# returns raw html from appropriate url
|
|
9
|
+
html = GatherData::WeatherChannelToday.return_html(zip)
|
|
10
|
+
|
|
11
|
+
# returns applicable data to be used to create object
|
|
12
|
+
weather_hash = ParseData::WeatherChannelToday.new(html).return_hash
|
|
13
|
+
|
|
14
|
+
today = Forecast::Day.new(weather_hash)
|
|
15
|
+
WeatherCard::SevenLines.new(today).display
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class FiveDay
|
|
20
|
+
|
|
21
|
+
def self.display(zip='72703')
|
|
22
|
+
html = GatherData::WeatherChannelFiveDay.return_html(zip)
|
|
23
|
+
weather_hashes = ParseData::WeatherChannelFiveDay.new(html).return_hash
|
|
24
|
+
WeatherCard::FiveLines.reset
|
|
25
|
+
weather_hashes.each do |weather|
|
|
26
|
+
day = Forecast::Day.new(weather)
|
|
27
|
+
WeatherCard::FiveLines.new(day)
|
|
28
|
+
end
|
|
29
|
+
WeatherCard::FiveLines.display
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Hourly
|
|
34
|
+
def self.display(zip='72703')
|
|
35
|
+
html = GatherData::WeatherChannelHourly.return_html(zip)
|
|
36
|
+
weather_hashes = ParseData::WeatherChannelHourly.new(html).return_hash
|
|
37
|
+
WeatherCard::Hourly.reset
|
|
38
|
+
weather_hashes.each do |weather|
|
|
39
|
+
day = Forecast::Day.new(weather)
|
|
40
|
+
WeatherCard::Hourly.new(day)
|
|
41
|
+
end
|
|
42
|
+
WeatherCard::Hourly.display
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
data/lib/weathercard.rb
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
module WeatherCard
|
|
2
|
+
|
|
3
|
+
# a class for creating weather cards to be easily and consistently displayed
|
|
4
|
+
# each card type will be unique to the data it displays
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
class FiveLines
|
|
8
|
+
# -------------
|
|
9
|
+
# |day |
|
|
10
|
+
# |H:xxx L:xxx|
|
|
11
|
+
# |shortdetail|
|
|
12
|
+
# |xx wind |
|
|
13
|
+
# |h:xxx p:xxx|
|
|
14
|
+
# -------------
|
|
15
|
+
attr_accessor :day #=> receives day object
|
|
16
|
+
@@all = []
|
|
17
|
+
@@length = 11
|
|
18
|
+
@@horizontal = '-'.colorize(:light_yellow)
|
|
19
|
+
@@vertical = '|'.colorize(:light_yellow)
|
|
20
|
+
|
|
21
|
+
extend WeatherCard::ClassMethods
|
|
22
|
+
include WeatherCard::InstanceMethods
|
|
23
|
+
|
|
24
|
+
def self.length
|
|
25
|
+
@@length
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.horizontal
|
|
29
|
+
@@horizontal
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.vertical
|
|
33
|
+
@@vertical
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.all
|
|
37
|
+
@@all
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def line_one
|
|
42
|
+
line_end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def line_two
|
|
46
|
+
str_length = day.day.length
|
|
47
|
+
remainder = @@length - str_length
|
|
48
|
+
spaces = ' ' * (remainder)
|
|
49
|
+
"#{@@vertical}#{day.day}#{spaces}#{@@vertical}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def line_three
|
|
53
|
+
str_length = day.min.length + day.max.length + 4
|
|
54
|
+
remainder = @@length - str_length
|
|
55
|
+
spaces = ' ' * (remainder)
|
|
56
|
+
"#{@@vertical}H:#{day.max.colorize(:light_red)}#{spaces}L:#{day.min.colorize(:light_blue)}#{@@vertical}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def line_four
|
|
60
|
+
str_length = day.short_detail.length
|
|
61
|
+
if str_length < @@length
|
|
62
|
+
remainder = @@length - str_length
|
|
63
|
+
spaces = ' ' * (remainder)
|
|
64
|
+
else
|
|
65
|
+
spaces = ''
|
|
66
|
+
end
|
|
67
|
+
"#{@@vertical}#{day.short_detail.slice(0..10)}#{spaces}#{@@vertical}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def line_five
|
|
71
|
+
str_length = day.wind_magnitude.length + day.wind_direction.length + day.wind_units.length
|
|
72
|
+
remainder = @@length - str_length
|
|
73
|
+
spaces = ' ' * (remainder - 1)
|
|
74
|
+
"#{@@vertical}#{day.wind_direction} #{day.wind_magnitude}#{day.wind_units}#{spaces}#{@@vertical}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def line_six
|
|
78
|
+
str_length = [day.precipitation.length,3].min + [day.humidity.length,3].min + 4
|
|
79
|
+
remainder = @@length - str_length
|
|
80
|
+
spaces = ' ' * (remainder)
|
|
81
|
+
"#{@@vertical}h:#{day.humidity.slice(0..2)}#{spaces}p:#{day.precipitation.slice(0..2)}#{@@vertical}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def line_seven
|
|
85
|
+
line_one
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def self.display
|
|
89
|
+
row1 = ''
|
|
90
|
+
row2 = ''
|
|
91
|
+
row3 = ''
|
|
92
|
+
row4 = ''
|
|
93
|
+
row5 = ''
|
|
94
|
+
row6 = ''
|
|
95
|
+
row7 = ''
|
|
96
|
+
@@all.each do |day|
|
|
97
|
+
row1 += day.line_one
|
|
98
|
+
row2 += day.line_two
|
|
99
|
+
row3 += day.line_three
|
|
100
|
+
row4 += day.line_four
|
|
101
|
+
row5 += day.line_five
|
|
102
|
+
row6 += day.line_six
|
|
103
|
+
row7 += day.line_seven
|
|
104
|
+
end
|
|
105
|
+
puts row1
|
|
106
|
+
puts row2
|
|
107
|
+
puts row3
|
|
108
|
+
puts row4
|
|
109
|
+
puts row5
|
|
110
|
+
puts row6
|
|
111
|
+
puts row7
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
class SevenLines
|
|
116
|
+
# 1 ---------------------------------
|
|
117
|
+
# 2 | dayText short_detail |
|
|
118
|
+
# 3 | H:xxx L:xxx Current:xxx |
|
|
119
|
+
# 4 | UV:xxxxxxx sunrise:xxxxxxx |
|
|
120
|
+
# 5 | wind:xxxxxxxx sunset:xxxxxxx |
|
|
121
|
+
# 6 | humidity:xxxx precip:xxxx |
|
|
122
|
+
# 7 | panel1 low:xxx |
|
|
123
|
+
# 8 | panel1 precip:xxx |
|
|
124
|
+
# 9 ---------------------------------
|
|
125
|
+
attr_accessor :day
|
|
126
|
+
@@all = []
|
|
127
|
+
@@length = 31
|
|
128
|
+
@@horizontal = '-'.colorize(:light_yellow)
|
|
129
|
+
@@vertical = '|'.colorize(:light_yellow)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
extend WeatherCard::ClassMethods
|
|
133
|
+
include WeatherCard::InstanceMethods
|
|
134
|
+
|
|
135
|
+
# :day, :panel_1_name, :current_temp, :panel_1_temp, :panel_2_temp, :short_detail, panel_1_short_detail, :panel_2_short_detail
|
|
136
|
+
# :precipitation, :panel_1_precip, :panel_2_precip, :max, :min, :wind_direction, :wind_magnitude, :wind_units,
|
|
137
|
+
# :long_detail, :humidity, :uv_index, :sunrise, :sunset
|
|
138
|
+
|
|
139
|
+
def self.length
|
|
140
|
+
@@length
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def self.horizontal
|
|
144
|
+
@@horizontal
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def self.vertical
|
|
148
|
+
@@vertical
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def self.all
|
|
152
|
+
@@all
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def initialize(day)
|
|
156
|
+
self.day = day
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def line1
|
|
160
|
+
line_end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def line2
|
|
164
|
+
str_length = day.day.length + day.short_detail.length
|
|
165
|
+
spaces = return_spaces(str_length)
|
|
166
|
+
str = "#{day.day}#{spaces}#{day.short_detail}"
|
|
167
|
+
line_intermediate(str)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def line3
|
|
171
|
+
str_length = day.max.length + day.min.length + day.current_temp.length + 16
|
|
172
|
+
spaces = return_spaces(str_length)
|
|
173
|
+
str = "H:#{day.max.colorize(:light_red)} L:#{day.min.colorize(:light_blue)}#{spaces}Currently:#{day.current_temp}"
|
|
174
|
+
line_intermediate(str)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def line4
|
|
178
|
+
str_length = day.uv_index.length + day.sunrise.length + 11
|
|
179
|
+
spaces = return_spaces(str_length)
|
|
180
|
+
str = "UV:#{day.uv_index}#{spaces}feels like:#{day.feels_like}"
|
|
181
|
+
line_intermediate(str)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def line5
|
|
185
|
+
str_length = day.wind_magnitude.length + day.wind_direction.length + day.wind_units.length + day.sunset.length + 13
|
|
186
|
+
spaces = return_spaces(str_length)
|
|
187
|
+
str = "wind:#{day.wind_direction}#{day.wind_magnitude}#{day.wind_units}#{spaces}sunrise #{day.sunrise}"
|
|
188
|
+
line_intermediate(str)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def line6
|
|
192
|
+
str_length = day.humidity.length + day.sunset.length + 16
|
|
193
|
+
spaces = return_spaces(str_length)
|
|
194
|
+
str = "humidity:#{day.humidity}#{spaces}sunset #{day.sunset}"
|
|
195
|
+
line_intermediate(str)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def line7
|
|
199
|
+
str_length = day.panel1_name.length + day.panel1_temp.length + 5
|
|
200
|
+
spaces = return_spaces(str_length)
|
|
201
|
+
str = "#{day.panel1_name} low:#{day.panel1_temp}#{spaces}"
|
|
202
|
+
line_intermediate(str)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def line8
|
|
206
|
+
str_length = day.panel1_name.length + day.panel1_precip.length + 8
|
|
207
|
+
spaces = return_spaces(str_length)
|
|
208
|
+
str = "#{day.panel1_name} precip:#{day.panel1_precip}#{spaces}"
|
|
209
|
+
line_intermediuate(str)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def line9
|
|
213
|
+
line1
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def display
|
|
217
|
+
puts line1
|
|
218
|
+
puts line2
|
|
219
|
+
puts line3
|
|
220
|
+
puts line4
|
|
221
|
+
puts line5
|
|
222
|
+
puts line6
|
|
223
|
+
detail
|
|
224
|
+
puts line9
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def detail
|
|
228
|
+
words = day.long_detail.split(' ')
|
|
229
|
+
while words.length > 0 do
|
|
230
|
+
new_string = ''
|
|
231
|
+
while new_string.length + words[0].length < @@length do
|
|
232
|
+
new_string += words.shift
|
|
233
|
+
new_string += ' '
|
|
234
|
+
break if words == []
|
|
235
|
+
end
|
|
236
|
+
spaces = return_spaces(new_string.length)
|
|
237
|
+
new_string = "#{new_string.colorize(:light_yellow)}#{spaces}"
|
|
238
|
+
puts line_intermediate(new_string)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
class Hourly
|
|
244
|
+
# -------------
|
|
245
|
+
# |dayTime |
|
|
246
|
+
# |temp feels |
|
|
247
|
+
# |shortdetail|
|
|
248
|
+
# |xx wind |
|
|
249
|
+
# |h:xxx p:xxx|
|
|
250
|
+
# -------------
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
attr_accessor :day #=> receives day object
|
|
254
|
+
@@all = []
|
|
255
|
+
@@length = 11
|
|
256
|
+
@@horizontal = '-'.colorize(:light_yellow)
|
|
257
|
+
@@vertical = '|'.colorize(:light_yellow)
|
|
258
|
+
|
|
259
|
+
extend WeatherCard::ClassMethods
|
|
260
|
+
include WeatherCard::InstanceMethods
|
|
261
|
+
|
|
262
|
+
def self.length
|
|
263
|
+
@@length
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def self.horizontal
|
|
267
|
+
@@horizontal
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def self.vertical
|
|
271
|
+
@@vertical
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def self.all
|
|
275
|
+
@@all
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def line1
|
|
279
|
+
line_end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def line2
|
|
283
|
+
str_length = day.day.length
|
|
284
|
+
spaces = return_spaces(str_length)
|
|
285
|
+
str = "#{day.day.colorize(:light_green)}#{spaces}"
|
|
286
|
+
line_intermediate(str)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def line3
|
|
290
|
+
str_length = day.current_temp.length + 6
|
|
291
|
+
spaces = return_spaces(str_length)
|
|
292
|
+
str = "curr: #{day.current_temp}#{spaces}"
|
|
293
|
+
line_intermediate(str)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def line4
|
|
297
|
+
str_length = day.feels_like.length + 7
|
|
298
|
+
spaces = return_spaces(str_length)
|
|
299
|
+
str = "feels: #{day.feels_like}#{spaces}"
|
|
300
|
+
line_intermediate(str)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def line5
|
|
304
|
+
str_length = [day.short_detail.length, 11].min
|
|
305
|
+
spaces = return_spaces(str_length)
|
|
306
|
+
str = "#{day.short_detail[0..10]}#{spaces}"
|
|
307
|
+
line_intermediate(str)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def line6
|
|
311
|
+
str_length = day.wind_magnitude.length
|
|
312
|
+
spaces = return_spaces(str_length)
|
|
313
|
+
str = "#{day.wind_magnitude}#{spaces}"
|
|
314
|
+
line_intermediate(str)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def line7
|
|
318
|
+
str_length = day.humidity.length + day.precipitation.length + 4
|
|
319
|
+
spaces = return_spaces(str_length)
|
|
320
|
+
str = "h:#{day.humidity}#{spaces}p:#{day.precipitation}"
|
|
321
|
+
line_intermediate(str)
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def line8
|
|
325
|
+
line1
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def self.display
|
|
329
|
+
beginning = 0
|
|
330
|
+
final = 5
|
|
331
|
+
n = (self.length / 6.0 + 0.5).to_i
|
|
332
|
+
n.times do
|
|
333
|
+
row1 = ''
|
|
334
|
+
row2 = ''
|
|
335
|
+
row3 = ''
|
|
336
|
+
row4 = ''
|
|
337
|
+
row5 = ''
|
|
338
|
+
row6 = ''
|
|
339
|
+
row7 = ''
|
|
340
|
+
row8 = ''
|
|
341
|
+
self.all[beginning..final].each do |weather|
|
|
342
|
+
row1 += weather.line1
|
|
343
|
+
row2 += weather.line2
|
|
344
|
+
row3 += weather.line3
|
|
345
|
+
row4 += weather.line4
|
|
346
|
+
row5 += weather.line5
|
|
347
|
+
row6 += weather.line6
|
|
348
|
+
row7 += weather.line7
|
|
349
|
+
row8 += weather.line8
|
|
350
|
+
end
|
|
351
|
+
beginning += 6
|
|
352
|
+
final += 6
|
|
353
|
+
puts row1
|
|
354
|
+
puts row2
|
|
355
|
+
puts row3
|
|
356
|
+
puts row4
|
|
357
|
+
puts row5
|
|
358
|
+
puts row6
|
|
359
|
+
puts row7
|
|
360
|
+
puts row8
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
end
|