Class: ParseData::WeatherChannelHourly

Inherits:
Object
  • Object
show all
Defined in:
lib/parse_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#htmlObject

Returns the value of attribute html.



265
266
267
# File 'lib/parse_data.rb', line 265

def html
  @html
end

Instance Method Details

#daysObject



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

#feelsObject



305
306
307
# File 'lib/parse_data.rb', line 305

def feels
    values('feels')
end

#humiditiesObject



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

#namesObject



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

#precipsObject



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_hashObject



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_detailsObject



296
297
298
299
# File 'lib/parse_data.rb', line 296

def short_details
    a = values('hidden-cell-sm.description')
    a
end

#tempsObject



301
302
303
# File 'lib/parse_data.rb', line 301

def temps
    values('temp')
end

#timesObject



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

#windsObject



341
342
343
# File 'lib/parse_data.rb', line 341

def winds
    values('wind')
end