Class: ParseData::WeatherChannelHourly
- Inherits:
-
Object
- Object
- ParseData::WeatherChannelHourly
- Defined in:
- lib/parse_data.rb
Instance Attribute Summary collapse
-
#html ⇒ Object
Returns the value of attribute html.
Instance Method Summary collapse
- #days ⇒ Object
- #feels ⇒ Object
- #humidities ⇒ Object
-
#initialize(doc) ⇒ WeatherChannelHourly
constructor
A new instance of WeatherChannelHourly.
- #names ⇒ Object
- #precips ⇒ Object
- #return_hash ⇒ Object
- #short_details ⇒ Object
- #temps ⇒ Object
- #times ⇒ Object
- #values(value) ⇒ Object
- #winds ⇒ Object
Constructor Details
#initialize(doc) ⇒ WeatherChannelHourly
Returns a new instance of WeatherChannelHourly.
267 268 269 |
# File 'lib/parse_data.rb', line 267 def initialize(doc) self.html = Nokogiri::HTML(doc) end |
Instance Attribute Details
#html ⇒ Object
Returns the value of attribute html.
265 266 267 |
# File 'lib/parse_data.rb', line 265 def html @html end |
Instance Method Details
#days ⇒ Object
335 336 337 338 339 |
# File 'lib/parse_data.rb', line 335 def days self.html.css('tbody div.hourly-date').collect do |day| day.text end end |
#feels ⇒ Object
305 306 307 |
# File 'lib/parse_data.rb', line 305 def feels values('feels') end |
#humidities ⇒ Object
319 320 321 322 323 324 325 326 327 |
# File 'lib/parse_data.rb', line 319 def humidities items = values('humidity') items.each do |item| if item.length < 2 items.delete(item) end end items end |
#names ⇒ Object
284 285 286 287 288 |
# File 'lib/parse_data.rb', line 284 def names days.zip(times).collect do |day, time| "#{time}".gsub(' ', '') end end |
#precips ⇒ Object
309 310 311 312 313 314 315 316 317 |
# File 'lib/parse_data.rb', line 309 def precips items = values('precip') items.each do |item| if item.length < 2 items.delete(item) end end items end |
#return_hash ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/parse_data.rb', line 271 def return_hash names.collect.with_index do |name, i| { :day => name, :current_temp => temps[i], :feels_like => feels[i], :wind_magnitude => winds[i], :humidity => humidities[i], :precipitation => precips[i], :short_detail => short_details[i] } end end |
#short_details ⇒ Object
296 297 298 299 |
# File 'lib/parse_data.rb', line 296 def short_details a = values('hidden-cell-sm.description') a end |
#temps ⇒ Object
301 302 303 |
# File 'lib/parse_data.rb', line 301 def temps values('temp') end |
#times ⇒ Object
329 330 331 332 333 |
# File 'lib/parse_data.rb', line 329 def times self.html.css('tbody div.hourly-time span').collect do |time| time.text end end |
#values(value) ⇒ Object
290 291 292 293 294 |
# File 'lib/parse_data.rb', line 290 def values(value) self.html.css("tbody td.#{value} span").collect do |item| item.text end end |
#winds ⇒ Object
341 342 343 |
# File 'lib/parse_data.rb', line 341 def winds values('wind') end |