noaaer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/noaaer/forecast.rb +8 -8
- data/lib/noaaer/http_service.rb +3 -3
- data/lib/noaaer/station_writer.rb +3 -3
- data/lib/noaaer/version.rb +1 -1
- metadata +1 -1
data/lib/noaaer/forecast.rb
CHANGED
@@ -24,7 +24,7 @@ module Noaaer
|
|
24
24
|
# The number of days provided by the forecast
|
25
25
|
#
|
26
26
|
def length
|
27
|
-
@length ||= @doc.
|
27
|
+
@length ||= @doc.xpath(%q{/dwml/data/time-layout[@summarization='24hourly'][1]/start-valid-time}).length
|
28
28
|
end
|
29
29
|
|
30
30
|
#
|
@@ -58,37 +58,37 @@ module Noaaer
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def starts
|
61
|
-
@starts ||= @doc.
|
61
|
+
@starts ||= @doc.xpath(%q{/dwml/data/time-layout[@summarization='24hourly'][1]/start-valid-time/text()}).map do |node|
|
62
62
|
Time.parse(node.to_s)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def ends
|
67
|
-
@ends ||= @doc.
|
67
|
+
@ends ||= @doc.xpath(%q{/dwml/data/time-layout[@summarization='24hourly'][1]/end-valid-time/text()}).map do |node|
|
68
68
|
Time.parse(node.to_s)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
def maxima
|
73
|
-
@maxima ||= @doc.
|
73
|
+
@maxima ||= @doc.xpath(%q{/dwml/data/parameters[1]/temperature[@type='maximum'][@units='Fahrenheit'][1]/value/text()}).map do |node|
|
74
74
|
node.to_s.to_i
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
def minima
|
79
|
-
@minima ||= @doc.
|
79
|
+
@minima ||= @doc.xpath(%q{/dwml/data/parameters[1]/temperature[@type='minimum'][@units='Fahrenheit'][1]/value/text()}).map do |node|
|
80
80
|
node.to_s.to_i
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
def weather_summaries
|
85
|
-
@weather_summaries ||= @doc.
|
85
|
+
@weather_summaries ||= @doc.xpath(%q{/dwml/data/parameters[1]/weather[1]/weather-conditions}).map do |node|
|
86
86
|
node['weather-summary'].to_s
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
def image_urls
|
91
|
-
@image_urls ||= @doc.
|
91
|
+
@image_urls ||= @doc.xpath(%q{/dwml/data/parameters[1]/conditions-icon/icon-link/text()}).map do |node|
|
92
92
|
node.to_s
|
93
93
|
end
|
94
94
|
end
|
@@ -100,7 +100,7 @@ module Noaaer
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def precipitation_probabilities
|
103
|
-
@precipitation_probabilities ||= @doc.
|
103
|
+
@precipitation_probabilities ||= @doc.xpath(%q{/dwml/data/parameters[1]/probability-of-precipitation[1]/value/text()}).map do |node|
|
104
104
|
node.to_s.to_i
|
105
105
|
end
|
106
106
|
end
|
data/lib/noaaer/http_service.rb
CHANGED
@@ -7,15 +7,15 @@ module Noaaer
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_current_conditions(station_id)
|
10
|
-
@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/#{station_id}.xml"))
|
10
|
+
Nokogiri::XML.parse(@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/#{station_id}.xml")))
|
11
11
|
end
|
12
12
|
|
13
13
|
def get_forecast(num_days, lat, lng)
|
14
|
-
@HTTP.get(URI.parse("http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=#{lat}&lon=#{lng}&format=24+hourly&numDays=#{num_days}"))
|
14
|
+
Nokogiri::XML.parse(@HTTP.get(URI.parse("http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=#{lat}&lon=#{lng}&format=24+hourly&numDays=#{num_days}")))
|
15
15
|
end
|
16
16
|
|
17
17
|
def get_station_list
|
18
|
-
@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/index.xml"))
|
18
|
+
doc = Nokogiri::XML(@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/index.xml")))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module Noaaer
|
2
2
|
class StationWriter
|
3
3
|
def initialize(doc)
|
4
4
|
@doc = doc
|
5
5
|
end
|
6
6
|
|
7
7
|
def write(io)
|
8
|
-
YAML.dump(@doc.
|
8
|
+
YAML.dump(@doc.xpath('/wx_station_index/station').map { |node| node_to_hash(node) }, io)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -20,7 +20,7 @@ module Noaeer
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def node_value(node, element)
|
23
|
-
node.
|
23
|
+
node.xpath("./#{element}/text()").first.to_s
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/noaaer/version.rb
CHANGED