Class: ParseData::WeatherChannelFiveDay
- Inherits:
-
Object
- Object
- ParseData::WeatherChannelFiveDay
- Defined in:
- lib/parse_data.rb
Instance Attribute Summary collapse
-
#html ⇒ Object
Returns the value of attribute html.
Instance Method Summary collapse
- #dates ⇒ Object
- #days ⇒ Object
- #forecast_temps ⇒ Object
- #forecast_wind ⇒ Object
- #humidities ⇒ Object
-
#initialize(doc) ⇒ WeatherChannelFiveDay
constructor
A new instance of WeatherChannelFiveDay.
- #long_details ⇒ Object
- #max_temps ⇒ Object
- #min_temps ⇒ Object
- #precips ⇒ Object
- #return_hash ⇒ Object
- #short_details ⇒ Object
- #wind_direction(wind_text) ⇒ Object
- #wind_directions ⇒ Object
- #wind_magnitude(wind_text) ⇒ Object
- #wind_magnitudes ⇒ Object
- #wind_unit(wind_text) ⇒ Object
- #wind_units ⇒ Object
- #wind_values ⇒ Object
Constructor Details
#initialize(doc) ⇒ WeatherChannelFiveDay
Returns a new instance of WeatherChannelFiveDay.
7 8 9 |
# File 'lib/parse_data.rb', line 7 def initialize(doc) self.html = Nokogiri::HTML(doc) end |
Instance Attribute Details
#html ⇒ Object
Returns the value of attribute html.
5 6 7 |
# File 'lib/parse_data.rb', line 5 def html @html end |
Instance Method Details
#dates ⇒ Object
35 36 37 38 39 |
# File 'lib/parse_data.rb', line 35 def dates self.html.css('body span.day-detail').collect do |date| date.text end end |
#days ⇒ Object
29 30 31 32 33 |
# File 'lib/parse_data.rb', line 29 def days self.html.css('body span.date-time').collect do |day| day.text end end |
#forecast_temps ⇒ Object
41 42 43 |
# File 'lib/parse_data.rb', line 41 def forecast_temps self.html.css('tbody td.temp div') end |
#forecast_wind ⇒ Object
57 58 59 |
# File 'lib/parse_data.rb', line 57 def forecast_wind self.html.css('tbody td.wind span') end |
#humidities ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/parse_data.rb', line 109 def humidities values = [] self.html.css('tbody td.humidity span span').each do |humidity| if humidity.text != "%" values << humidity.text end end values end |
#long_details ⇒ Object
97 98 99 100 101 |
# File 'lib/parse_data.rb', line 97 def long_details self.html.css('tbody td.description').collect do |detail| detail.attribute('title').value end end |
#max_temps ⇒ Object
45 46 47 48 49 |
# File 'lib/parse_data.rb', line 45 def max_temps forecast_temps.collect do |temp| temp.css('span')[0].text end end |
#min_temps ⇒ Object
51 52 53 54 55 |
# File 'lib/parse_data.rb', line 51 def min_temps forecast_temps.collect do |temp| temp.css('span')[2].text end end |
#precips ⇒ Object
119 120 121 122 123 |
# File 'lib/parse_data.rb', line 119 def precips self.html.css('tbody td.precip div').collect do |precip| precip.text end end |
#return_hash ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/parse_data.rb', line 11 def return_hash # available instance variable for forecast class are => # :day, :date, :max, :min, :wind_direction, :wind_magnitude, :wind_units, :date, :short_detail, :long_detail, :humidity days.collect.with_index do |day, i| { :day => days[i], :date => dates[i], :max => max_temps[i], :min => min_temps[i], :wind_direction => wind_directions[i], :wind_magnitude => wind_magnitudes[i], :wind_units => wind_units[i], :short_detail => short_details[i], :long_detail => long_details[i], :humidity => humidities[i], :precipitation => precips[i]} end end |
#short_details ⇒ Object
103 104 105 106 107 |
# File 'lib/parse_data.rb', line 103 def short_details self.html.css('tbody td.description').collect do |detail| detail.text end end |
#wind_direction(wind_text) ⇒ Object
61 62 63 |
# File 'lib/parse_data.rb', line 61 def wind_direction(wind_text) wind_text.split(' ')[0] end |
#wind_directions ⇒ Object
79 80 81 82 83 |
# File 'lib/parse_data.rb', line 79 def wind_directions wind_values.collect do |wind| wind_direction(wind) end end |
#wind_magnitude(wind_text) ⇒ Object
65 66 67 |
# File 'lib/parse_data.rb', line 65 def wind_magnitude(wind_text) wind_text.split(' ')[1] end |
#wind_magnitudes ⇒ Object
85 86 87 88 89 |
# File 'lib/parse_data.rb', line 85 def wind_magnitudes wind_values.collect do |wind| wind_magnitude(wind) end end |
#wind_unit(wind_text) ⇒ Object
69 70 71 |
# File 'lib/parse_data.rb', line 69 def wind_unit(wind_text) wind_text.split(' ')[2] end |
#wind_units ⇒ Object
91 92 93 94 95 |
# File 'lib/parse_data.rb', line 91 def wind_units wind_values.collect do |wind| wind_unit(wind) end end |
#wind_values ⇒ Object
73 74 75 76 77 |
# File 'lib/parse_data.rb', line 73 def wind_values forecast_wind.collect do |wind| wind.text end end |