Class: ParseData::WeatherChannelFiveDay

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#htmlObject

Returns the value of attribute html.



5
6
7
# File 'lib/parse_data.rb', line 5

def html
  @html
end

Instance Method Details

#datesObject



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

#daysObject



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_tempsObject



41
42
43
# File 'lib/parse_data.rb', line 41

def forecast_temps
    self.html.css('tbody td.temp div')
end

#forecast_windObject



57
58
59
# File 'lib/parse_data.rb', line 57

def forecast_wind
    self.html.css('tbody td.wind span')
end

#humiditiesObject



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_detailsObject



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_tempsObject



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_tempsObject



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

#precipsObject



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_hashObject



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_detailsObject



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_directionsObject



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_magnitudesObject



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_unitsObject



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_valuesObject



73
74
75
76
77
# File 'lib/parse_data.rb', line 73

def wind_values
    forecast_wind.collect do |wind|                
        wind.text
    end
end