class ParseData::WeatherChannelFiveDay

Attributes

html[RW]

Public Class Methods

new(doc) click to toggle source
# File lib/parse_data.rb, line 7
def initialize(doc)
    self.html = Nokogiri::HTML(doc)
end

Public Instance Methods

dates() click to toggle source
# File lib/parse_data.rb, line 35
def dates
    self.html.css('body span.day-detail').collect do |date|
        date.text
    end
end
days() click to toggle source
# 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() click to toggle source
# File lib/parse_data.rb, line 41
def forecast_temps
    self.html.css('tbody td.temp div')
end
forecast_wind() click to toggle source
# File lib/parse_data.rb, line 57
def forecast_wind
    self.html.css('tbody td.wind span')
end
humidities() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/parse_data.rb, line 45
def max_temps
    forecast_temps.collect do |temp|
        temp.css('span')[0].text
    end
end
min_temps() click to toggle source
# File lib/parse_data.rb, line 51
def min_temps
    forecast_temps.collect do |temp|
        temp.css('span')[2].text
    end
end
precips() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/parse_data.rb, line 61
def wind_direction(wind_text)
    wind_text.split(' ')[0]
end
wind_directions() click to toggle source
# File lib/parse_data.rb, line 79
def wind_directions
    wind_values.collect do |wind|
        wind_direction(wind)
    end
end
wind_magnitude(wind_text) click to toggle source
# File lib/parse_data.rb, line 65
def wind_magnitude(wind_text)
    wind_text.split(' ')[1]
end
wind_magnitudes() click to toggle source
# File lib/parse_data.rb, line 85
def wind_magnitudes
    wind_values.collect do |wind|
        wind_magnitude(wind)
    end
end
wind_unit(wind_text) click to toggle source
# File lib/parse_data.rb, line 69
def wind_unit(wind_text)
    wind_text.split(' ')[2]
end
wind_units() click to toggle source
# File lib/parse_data.rb, line 91
def wind_units
    wind_values.collect do |wind|
        wind_unit(wind)
    end
end
wind_values() click to toggle source
# File lib/parse_data.rb, line 73
def wind_values
    forecast_wind.collect do |wind|                
        wind.text
    end
end