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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3ddbd4fa1cda61f47cc0bb524c270b42863623a5d470c42650e8b9fbb044af87
4
+ data.tar.gz: 3d71434443eafe26eb497bfae47e7a81c4ddb0e84ca3cbc38717bdbedd90c1ac
5
+ SHA512:
6
+ metadata.gz: 1f595fc1f8955d0671b7adb621aa4bee1afda8761f4ca1ecd774952f31f7f8286e0a2005087532ca453012231a94fa6650bf0b118e9ad9ed652f5c7a09874930
7
+ data.tar.gz: 1765ab2d5284e017365a10971d1dbc8b8fe563ca2d4c0c195638333969216176336bd56cbc760ce60b39b7893a28c33d5db93a37ce1fe57ba5cadb9453071c03
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ lib/test.rb
10
+ fixtures
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at brad.schrag@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "nokogiri"
4
+ gem "gem_menu"
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ colorize (0.8.1)
5
+ gem_menu (0.2.1)
6
+ colorize (~> 0.8.1)
7
+ mini_portile2 (2.3.0)
8
+ nokogiri (1.8.5)
9
+ mini_portile2 (~> 2.3.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ gem_menu
16
+ nokogiri
17
+
18
+ BUNDLED WITH
19
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 brad schrag
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # WeatherCLI
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/weatherCLI`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'weatherCLI'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install weatherCLI
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/weatherCLI. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the WeatherCLI project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/weatherCLI/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "weatherCLI"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require 'nokogiri'
2
+ require 'gem_menu'
3
+ require 'open-uri'
4
+ require 'json'
5
+ require './lib/parse_data'
6
+ require './lib/concerns/modules'
7
+ require './lib/concerns/weathercard'
8
+ require './lib/concerns/return_html'
9
+ require './lib/concerns/menus'
10
+ require './lib/weatherCLI/version'
11
+ require './lib/forecast'
12
+ require './lib/weathercard'
13
+ require './lib/settings'
14
+ require './lib/gather_data'
15
+
16
+
17
+ SETTINGS_PATH = './config/settings'
18
+ Settings.init
data/config/settings ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "zip_codes": [
3
+ "72703",
4
+ "72762",
5
+ "81504"
6
+ ]
7
+ }
@@ -0,0 +1,56 @@
1
+ module Menus
2
+ def choose_forecast(zip)
3
+ entries = []
4
+ entries << GemMenu::Entry.new("5 day forecast", method(:display_5_day), {:parameters => zip})
5
+ entries << GemMenu::Entry.new("Single day detail", method(:display_single_detail), {:parameters => zip})
6
+ entries << GemMenu::Entry.new("Hourly", method(:display_hourly), {:parameters => zip})
7
+ optional = {:previous_menu => method(:main_menu)}
8
+ GemMenu::Menu.new("Choose forecast to view", entries, optional_args=optional)
9
+ end
10
+
11
+ def main_menu
12
+ zips = Settings.zip_codes
13
+ entries = []
14
+ zips.each do |zip|
15
+ entries << GemMenu::Entry.new(zip, method(:choose_forecast), optional_args = {:parameters => zip})
16
+ end
17
+ entries << GemMenu::Entry.new("Add zip code", method(:add_zip))
18
+ entries << GemMenu::Entry.new("Remove zip code", method(:remove_zip))
19
+ GemMenu::Menu.new("Choose a zipcode to view forecast", entries)
20
+ end
21
+
22
+ def remove_zip
23
+ entries = []
24
+ Settings.zip_codes.each do |zip|
25
+ entries << GemMenu::Entry.new(zip, method(:delete_zip), optional_args={:parameters => zip})
26
+ end
27
+ GemMenu::Menu.new("Select zipcode to remove", entries, optional_args={:previous_menu => method(:main_menu)})
28
+ end
29
+
30
+ def display_5_day(zip)
31
+ WeatherCLI::FiveDay.display(zip)
32
+ choose_forecast(zip)
33
+ end
34
+
35
+ def display_single_detail(zip)
36
+ WeatherCLI::SingleDay.display(zip)
37
+ choose_forecast(zip)
38
+ end
39
+
40
+ def display_hourly(zip)
41
+ WeatherCLI::Hourly.display(zip)
42
+ choose_forecast(zip)
43
+ end
44
+
45
+ def add_zip
46
+ puts "Please enter the zip code:".colorize(:light_green)
47
+ zip = gets.strip
48
+ Settings.add_zip(zip)
49
+ main_menu
50
+ end
51
+
52
+ def delete_zip(zip)
53
+ Settings.remove_zip(zip)
54
+ remove_zip
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ module Modules
2
+ module MassInitialize
3
+ module InstanceMethods
4
+ def initialize(args)
5
+ args.each do |key, value|
6
+ self.send("#{key}=", value)
7
+ end
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # module for class methods of returning HTML
2
+
3
+ module ReturnHTML
4
+ module ClassMethods
5
+
6
+ def return_html(zip)
7
+ full_url = "#{self.url}#{zip}"
8
+ begin
9
+ open(full_url, &:read)
10
+ rescue OpenURI::HTTPError
11
+ puts "#{zip} is not found on weather.com. Consider removing it from your list.".colorize(:light_red)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module WeatherCard
2
+ module ClassMethods
3
+ def reset
4
+ self.all.clear
5
+ end
6
+
7
+ end
8
+
9
+ module InstanceMethods
10
+ def initialize(day)
11
+ self.day = day
12
+ self.class.all << self
13
+ end
14
+
15
+ def return_spaces(length)
16
+ ' ' * (self.class.length - length)
17
+ end
18
+
19
+ def line_end
20
+ self.class.horizontal * (self.class.length + 2)
21
+ end
22
+
23
+ def line_intermediate(value)
24
+ "#{self.class.vertical}#{value}#{self.class.vertical}"
25
+ end
26
+ end
27
+ end
data/lib/forecast.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Forecast
2
+ class Day
3
+ attr_accessor :day, :date, :max, :min, :temperature_units, :wind_direction, :wind_magnitude, :wind_units, :short_detail,
4
+ :long_detail, :humidity, :precipitation,:panel0_name,:panel1_name, :panel2_name,:panel0_temp,:panel1_temp,
5
+ :panel2_temp,:panel0_short_detail,:panel1_short_detail,:panel2_short_detail, :panel0_precip, :panel1_precip,
6
+ :panel2_precip, :current_temp, :overnight_temp, :uv_index, :sunrise, :sunset, :overnight_precipitation, :feels_like
7
+
8
+ include Modules::MassInitialize::InstanceMethods
9
+ end
10
+
11
+ end
@@ -0,0 +1,38 @@
1
+ # module for housing the various classes of data to gather
2
+ # each class will have a unique url. The ReturnHTML module has the methods for
3
+ # retreiving the data
4
+
5
+ module GatherData
6
+ class WeatherChannelFiveDay
7
+ @@url = 'https://weather.com/weather/5day/l/'
8
+
9
+ extend ReturnHTML::ClassMethods
10
+
11
+ def self.url
12
+ @@url
13
+ end
14
+ end
15
+
16
+ class WeatherChannelToday
17
+ @@url = 'https://weather.com/weather/today/l/'
18
+
19
+ extend ReturnHTML::ClassMethods
20
+
21
+ def self.url
22
+ @@url
23
+ end
24
+ end
25
+
26
+ class WeatherChannelHourly
27
+ @@url = 'https://weather.com/weather/hourbyhour/l/'
28
+
29
+ extend ReturnHTML::ClassMethods
30
+
31
+ def self.url
32
+ @@url
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+
data/lib/parse_data.rb ADDED
@@ -0,0 +1,345 @@
1
+ # module for sifting through a Nokogiri object to retrieve the desired properties
2
+
3
+ module ParseData
4
+ class WeatherChannelFiveDay
5
+ attr_accessor :html
6
+
7
+ def initialize(doc)
8
+ self.html = Nokogiri::HTML(doc)
9
+ end
10
+
11
+ def return_hash
12
+ # available instance variable for forecast class are =>
13
+ # :day, :date, :max, :min, :wind_direction, :wind_magnitude, :wind_units, :date, :short_detail, :long_detail, :humidity
14
+ days.collect.with_index do |day, i|
15
+ { :day => days[i],
16
+ :date => dates[i],
17
+ :max => max_temps[i],
18
+ :min => min_temps[i],
19
+ :wind_direction => wind_directions[i],
20
+ :wind_magnitude => wind_magnitudes[i],
21
+ :wind_units => wind_units[i],
22
+ :short_detail => short_details[i],
23
+ :long_detail => long_details[i],
24
+ :humidity => humidities[i],
25
+ :precipitation => precips[i]}
26
+ end
27
+ end
28
+
29
+ def days
30
+ self.html.css('body span.date-time').collect do |day|
31
+ day.text
32
+ end
33
+ end
34
+
35
+ def dates
36
+ self.html.css('body span.day-detail').collect do |date|
37
+ date.text
38
+ end
39
+ end
40
+
41
+ def forecast_temps
42
+ self.html.css('tbody td.temp div')
43
+ end
44
+
45
+ def max_temps
46
+ forecast_temps.collect do |temp|
47
+ temp.css('span')[0].text
48
+ end
49
+ end
50
+
51
+ def min_temps
52
+ forecast_temps.collect do |temp|
53
+ temp.css('span')[2].text
54
+ end
55
+ end
56
+
57
+ def forecast_wind
58
+ self.html.css('tbody td.wind span')
59
+ end
60
+
61
+ def wind_direction(wind_text)
62
+ wind_text.split(' ')[0]
63
+ end
64
+
65
+ def wind_magnitude(wind_text)
66
+ wind_text.split(' ')[1]
67
+ end
68
+
69
+ def wind_unit(wind_text)
70
+ wind_text.split(' ')[2]
71
+ end
72
+
73
+ def wind_values
74
+ forecast_wind.collect do |wind|
75
+ wind.text
76
+ end
77
+ end
78
+
79
+ def wind_directions
80
+ wind_values.collect do |wind|
81
+ wind_direction(wind)
82
+ end
83
+ end
84
+
85
+ def wind_magnitudes
86
+ wind_values.collect do |wind|
87
+ wind_magnitude(wind)
88
+ end
89
+ end
90
+
91
+ def wind_units
92
+ wind_values.collect do |wind|
93
+ wind_unit(wind)
94
+ end
95
+ end
96
+
97
+ def long_details
98
+ self.html.css('tbody td.description').collect do |detail|
99
+ detail.attribute('title').value
100
+ end
101
+ end
102
+
103
+ def short_details
104
+ self.html.css('tbody td.description').collect do |detail|
105
+ detail.text
106
+ end
107
+ end
108
+
109
+ def humidities
110
+ values = []
111
+ self.html.css('tbody td.humidity span span').each do |humidity|
112
+ if humidity.text != "%"
113
+ values << humidity.text
114
+ end
115
+ end
116
+ values
117
+ end
118
+
119
+ def precips
120
+ self.html.css('tbody td.precip div').collect do |precip|
121
+ precip.text
122
+ end
123
+ end
124
+ end
125
+
126
+ class WeatherChannelToday
127
+ attr_accessor :html
128
+
129
+ def initialize(doc)
130
+ self.html = Nokogiri::HTML(doc)
131
+ end
132
+
133
+ def return_hash
134
+ { :day => panel0_text,
135
+ :panel1_name => panel1_text,
136
+ :panel2_name => panel2_text,
137
+ :current_temp => current_temp,
138
+ :panel1_temp => panel1_temp,
139
+ :panel2_temp => panel2_temp,
140
+ :short_detail => panel0_short_detail,
141
+ :panel1_short_detail => panel1_short_detail,
142
+ :panel2_short_detail => panel2_short_detail,
143
+ :precipitation => panel0_precip,
144
+ :panel1_precip => panel1_precip,
145
+ :panel2_precip => panel2_precip,
146
+ :max => max,
147
+ :min => min,
148
+ :wind_direction => wind_direction,
149
+ :wind_magnitude => wind_magnitude,
150
+ :wind_units => wind_units,
151
+ :long_detail => long_detail,
152
+ :humidity => humidity,
153
+ :uv_index => uv_index,
154
+ :sunrise => sunrise,
155
+ :sunset => sunset,
156
+ :feels_like => feels_like}
157
+ end
158
+
159
+ def feels_like
160
+ self.html.css('div.today_nowcard div.today_nowcard-feels span.deg-feels').text
161
+ end
162
+
163
+ def current_temp
164
+ self.html.css('div.today_nowcard div.today_nowcard-temp span').text
165
+ end
166
+
167
+ def max
168
+ self.html.css('div.today_nowcard-hilo span.deg-hilo-nowcard')[0].text
169
+ end
170
+
171
+ def min
172
+ self.html.css('div.today_nowcard-hilo span.deg-hilo-nowcard')[1].text
173
+ end
174
+
175
+ def wx_detail
176
+ self.html.css('div.looking-ahead.panel-footer li.wx-detail span.wx-detail-text span.wx-detail-value')
177
+ end
178
+
179
+ def wind
180
+ wx_detail[0].text
181
+ end
182
+
183
+ def wind_units
184
+ wind.split(' ')[2]
185
+ end
186
+
187
+ def wind_direction
188
+ wind.split(' ')[0]
189
+ end
190
+
191
+ def wind_magnitude
192
+ wind.split(' ')[1]
193
+ end
194
+
195
+ def humidity
196
+ wx_detail[1].text
197
+ end
198
+
199
+ def uv_index
200
+ wx_detail[2].text.sub(' ', '')
201
+ end
202
+
203
+ def sunrise
204
+ wx_detail.css('span#dp0-details-sunrise').text.sub(' ', '')
205
+ end
206
+
207
+ def sunset
208
+ wx_detail.css('span#dp0-details-sunset').text.sub(' ', '')
209
+ end
210
+
211
+ def long_detail
212
+ self.html.css('div.dp-details span#dp0-details-narrative').text
213
+ end
214
+
215
+ def panel0_precip
216
+ self.html.css('div#daypart-0 span.precip-val').text
217
+ end
218
+
219
+ def panel1_precip
220
+ self.html.css('div#daypart-1 span.precip-val').text
221
+ end
222
+
223
+ def panel2_precip
224
+ self.html.css('div#daypart-2 span.precip-val').text
225
+ end
226
+
227
+ def panel0_short_detail
228
+ self.html.css('div#daypart-0 span.today-daypart-wxphrase').text
229
+ end
230
+
231
+ def panel1_short_detail
232
+ self.html.css('div#daypart-1 span.today-daypart-wxphrase').text
233
+ end
234
+
235
+ def panel2_short_detail
236
+ self.html.css('div#daypart-2 span.today-daypart-wxphrase').text
237
+ end
238
+
239
+ def panel0_text
240
+ self.html.css('div#daypart-0 span.today-daypart-title').text
241
+ end
242
+
243
+ def panel1_text
244
+ self.html.css('div#daypart-1 span.today-daypart-title').text
245
+ end
246
+
247
+ def panel2_text
248
+ self.html.css('div#daypart-2 span.today-daypart-title').text
249
+ end
250
+
251
+ def panel0_temp
252
+ self.html.css('div#daypart-0 div.today-daypart-temp').text
253
+ end
254
+
255
+ def panel1_temp
256
+ self.html.css('div#daypart-1 div.today-daypart-temp').text
257
+ end
258
+
259
+ def panel2_temp
260
+ self.html.css('div#daypart-2 div.today-daypart-temp').text
261
+ end
262
+ end
263
+
264
+ class WeatherChannelHourly
265
+ attr_accessor :html
266
+
267
+ def initialize(doc)
268
+ self.html = Nokogiri::HTML(doc)
269
+ end
270
+
271
+ def return_hash
272
+ names.collect.with_index do |name, i|
273
+ { :day => name,
274
+ :current_temp => temps[i],
275
+ :feels_like => feels[i],
276
+ :wind_magnitude => winds[i],
277
+ :humidity => humidities[i],
278
+ :precipitation => precips[i],
279
+ :short_detail => short_details[i]
280
+ }
281
+ end
282
+ end
283
+
284
+ def names
285
+ days.zip(times).collect do |day, time|
286
+ "#{time}".gsub(' ', '')
287
+ end
288
+ end
289
+
290
+ def values(value)
291
+ self.html.css("tbody td.#{value} span").collect do |item|
292
+ item.text
293
+ end
294
+ end
295
+
296
+ def short_details
297
+ a = values('hidden-cell-sm.description')
298
+ a
299
+ end
300
+
301
+ def temps
302
+ values('temp')
303
+ end
304
+
305
+ def feels
306
+ values('feels')
307
+ end
308
+
309
+ def precips
310
+ items = values('precip')
311
+ items.each do |item|
312
+ if item.length < 2
313
+ items.delete(item)
314
+ end
315
+ end
316
+ items
317
+ end
318
+
319
+ def humidities
320
+ items = values('humidity')
321
+ items.each do |item|
322
+ if item.length < 2
323
+ items.delete(item)
324
+ end
325
+ end
326
+ items
327
+ end
328
+
329
+ def times
330
+ self.html.css('tbody div.hourly-time span').collect do |time|
331
+ time.text
332
+ end
333
+ end
334
+
335
+ def days
336
+ self.html.css('tbody div.hourly-date').collect do |day|
337
+ day.text
338
+ end
339
+ end
340
+
341
+ def winds
342
+ values('wind')
343
+ end
344
+ end
345
+ end