outoftime-noaa 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/noaa/current_conditions.rb +44 -0
- data/lib/noaa/forecast.rb +14 -0
- data/lib/noaa/forecast_day.rb +9 -1
- data/lib/noaa.rb +1 -1
- data/noaa.gemspec +6 -6
- data/test/test_current_conditions.rb +25 -13
- data/test/test_forecast.rb +12 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
data/README
CHANGED
data/Rakefile
CHANGED
|
@@ -14,7 +14,7 @@ Echoe.new('noaa', NOAA::VERSION) do |p|
|
|
|
14
14
|
p.description = 'Ruby API for National Oceanic and Atmospheric Administration weather data'
|
|
15
15
|
p.email = 'mat@patch.com'
|
|
16
16
|
p.url = 'http://github.com/outoftime/noaa'
|
|
17
|
-
p.install_message = "Be sure to update the weather station list:\n\n\
|
|
17
|
+
p.install_message = "Be sure to update the weather station list:\n\n\tsudo noaa-update-stations\n\nThis can be run at any time to update the stations, but you must run it once to initially populate the station list."
|
|
18
18
|
p.runtime_dependencies = [Gem::Dependency.new('libxml-ruby', '>= 0.9.7'),
|
|
19
19
|
Gem::Dependency.new('andre-geokit', '>= 1.2.0')]
|
|
20
20
|
p.development_dependencies = [Gem::Dependency.new('jeremymcanally-context', '>= 0.0.6'),
|
|
@@ -29,6 +29,50 @@ module NOAA
|
|
|
29
29
|
def weather_description
|
|
30
30
|
@weather_description ||= text_from_node('weather')
|
|
31
31
|
end
|
|
32
|
+
alias_method :weather_summary, :weather_description
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# NWS code representing weather type. This distills the #weather_description
|
|
36
|
+
# into one of a much more manageable set of possibilities. Possible values are:
|
|
37
|
+
#
|
|
38
|
+
# - <code>:skc</code> - Clear
|
|
39
|
+
# - <code>:wind</code> - Windy
|
|
40
|
+
# - <code>:few</code> - A Few Clouds
|
|
41
|
+
# - <code>:sct</code> - Partly Cloudy
|
|
42
|
+
# - <code>:bkn</code> - Mostly Cloudy
|
|
43
|
+
# - <code>:ovc</code> - Overcast
|
|
44
|
+
# - <code>:ra1</code> - Light Rain
|
|
45
|
+
# - <code>:ra</code> - Rain
|
|
46
|
+
# - <code>:shra</code> - Rain Showers
|
|
47
|
+
# - <code>:tsra</code> - Thunderstorms
|
|
48
|
+
# - <code>:ip</code> - Hail
|
|
49
|
+
# - <code>:fzra</code> - Freezing Rain
|
|
50
|
+
# - <code>:mix</code> - Wintry Mix
|
|
51
|
+
# - <code>:sn</code> - Snow
|
|
52
|
+
# - <code>:fg</code> - Fog
|
|
53
|
+
# - <code>:smoke</code> - Smoke
|
|
54
|
+
# - <code>:dust</code> - Dust/Sand
|
|
55
|
+
# - <code>:mist</code> - Haze
|
|
56
|
+
# - <code>:nsvrtsra</code> - Tornado
|
|
57
|
+
# - <code>:fzrara</code> - Freezing Rain/Rain
|
|
58
|
+
# - <code>:raip</code> - Rain/Hail
|
|
59
|
+
# - <code>:rasn</code> - Rain/Snow
|
|
60
|
+
# - <code>:hi_shwrs</code> - Showers in Vicinity
|
|
61
|
+
# - <code>:hi_tsra</code> - Thunderstorm in Vicinity
|
|
62
|
+
#
|
|
63
|
+
# See http://www.weather.gov/xml/current_obs/weather.php for the NWS's list of possible
|
|
64
|
+
# descriptions and their type codes.
|
|
65
|
+
#
|
|
66
|
+
def weather_type_code
|
|
67
|
+
@weather_type_code ||= text_from_node('icon_url_name').sub(/\.jpg$/, '').to_sym
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
# Return the NWS image URL for the current weather as string
|
|
72
|
+
#
|
|
73
|
+
def image_url
|
|
74
|
+
@image_url ||= "#{text_from_node('icon_url_base')}#{text_from_node('icon_url_name')}"
|
|
75
|
+
end
|
|
32
76
|
|
|
33
77
|
#
|
|
34
78
|
# The current temperature in the requested units.
|
data/lib/noaa/forecast.rb
CHANGED
|
@@ -48,6 +48,8 @@ module NOAA
|
|
|
48
48
|
day.high = maxima[i]
|
|
49
49
|
day.low = minima[i]
|
|
50
50
|
day.weather_summary = weather_summaries[i]
|
|
51
|
+
day.weather_type_code = weather_type_codes[i]
|
|
52
|
+
day.image_url = image_urls[i]
|
|
51
53
|
day.daytime_precipitation_probability = precipitation_probabilities[i*2]
|
|
52
54
|
day.evening_precipitation_probability = precipitation_probabilities[i*2+1]
|
|
53
55
|
end
|
|
@@ -85,6 +87,18 @@ module NOAA
|
|
|
85
87
|
end
|
|
86
88
|
end
|
|
87
89
|
|
|
90
|
+
def image_urls
|
|
91
|
+
@image_urls ||= @doc.find(%q{/dwml/data/parameters[1]/conditions-icon/icon-link/text()}).map do |node|
|
|
92
|
+
node.to_s
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def weather_type_codes
|
|
97
|
+
@weather_type_codes ||= image_urls.map do |url|
|
|
98
|
+
url.match(/n?([a-z_]+)\d*\.jpg$/)[1].to_sym
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
88
102
|
def precipitation_probabilities
|
|
89
103
|
@precipitation_probabilities ||= @doc.find(%q{/dwml/data/parameters[1]/probability-of-precipitation[1]/value/text()}).map do |node|
|
|
90
104
|
node.to_s.to_i
|
data/lib/noaa/forecast_day.rb
CHANGED
|
@@ -18,6 +18,13 @@ module NOAA
|
|
|
18
18
|
|
|
19
19
|
# String summary of weather (e.g., 'Fair')
|
|
20
20
|
attr_reader :weather_summary
|
|
21
|
+
alias_method :weather_description, :weather_summary
|
|
22
|
+
|
|
23
|
+
# Symbol representing NOAA weather type. See NOAA::CurrentConditions#weather_type_code
|
|
24
|
+
attr_reader :weather_type_code
|
|
25
|
+
|
|
26
|
+
# URL string for NOAA weather image
|
|
27
|
+
attr_reader :image_url
|
|
21
28
|
|
|
22
29
|
# Percentage probability of precipitation during the day, between 6am and 6pm, as an integer (0-100)
|
|
23
30
|
attr_reader :daytime_precipitation_probability
|
|
@@ -25,6 +32,7 @@ module NOAA
|
|
|
25
32
|
# Percentage probability of precipitation during the evening/night, between 6pm and 6am, as an integer (0-100)
|
|
26
33
|
attr_reader :evening_precipitation_probability
|
|
27
34
|
|
|
28
|
-
attr_writer :starts_at, :ends_at, :high, :low, :weather_summary, :
|
|
35
|
+
attr_writer :starts_at, :ends_at, :high, :low, :weather_summary, :weather_type_code, :image_url, #:nodoc:
|
|
36
|
+
:daytime_precipitation_probability, :evening_precipitation_probability #:nodoc:
|
|
29
37
|
end
|
|
30
38
|
end
|
data/lib/noaa.rb
CHANGED
data/noaa.gemspec
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{noaa}
|
|
5
|
-
s.version = "0.
|
|
5
|
+
s.version = "0.2.0"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Mat Brown"]
|
|
9
|
-
s.date = %q{2008-12-
|
|
9
|
+
s.date = %q{2008-12-30}
|
|
10
10
|
s.default_executable = %q{noaa-update-stations}
|
|
11
11
|
s.description = %q{Ruby API for National Oceanic and Atmospheric Administration weather data}
|
|
12
12
|
s.email = %q{mat@patch.com}
|
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
|
17
17
|
s.homepage = %q{http://github.com/outoftime/noaa}
|
|
18
18
|
s.post_install_message = %q{Be sure to update the weather station list:
|
|
19
19
|
|
|
20
|
-
noaa-update-stations
|
|
20
|
+
sudo noaa-update-stations
|
|
21
21
|
|
|
22
22
|
This can be run at any time to update the stations, but you must run it once to initially populate the station list.}
|
|
23
23
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Noaa", "--main", "README"]
|
|
@@ -34,9 +34,9 @@ This can be run at any time to update the stations, but you must run it once to
|
|
|
34
34
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
35
35
|
s.add_runtime_dependency(%q<libxml-ruby>, [">= 0.9.7"])
|
|
36
36
|
s.add_runtime_dependency(%q<andre-geokit>, [">= 1.2.0"])
|
|
37
|
-
s.
|
|
38
|
-
s.
|
|
39
|
-
s.
|
|
37
|
+
s.add_development_dependency(%q<jeremymcanally-context>, [">= 0.0.6"])
|
|
38
|
+
s.add_development_dependency(%q<jeremymcanally-matchy>, [">= 0.0.1"])
|
|
39
|
+
s.add_development_dependency(%q<ruby-debug>, ["~> 0.10"])
|
|
40
40
|
else
|
|
41
41
|
s.add_dependency(%q<libxml-ruby>, [">= 0.9.7"])
|
|
42
42
|
s.add_dependency(%q<andre-geokit>, [">= 1.2.0"])
|
|
@@ -11,25 +11,37 @@ class TestCurrentConditions < NOAA::TestCase
|
|
|
11
11
|
conditions.weather_description.should == 'Fair'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
test 'should return
|
|
15
|
-
conditions.
|
|
14
|
+
test 'should return weather description from #weather_summary' do
|
|
15
|
+
conditions.weather_summary.should == 'Fair'
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
test 'should return
|
|
19
|
-
conditions.
|
|
18
|
+
test 'should return weather type code' do
|
|
19
|
+
conditions.weather_type_code.should == :skc
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
test 'should return
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
test 'should return image URL' do
|
|
23
|
+
conditions.image_url.should == 'http://weather.gov/weather/images/fcicons/skc.jpg'
|
|
24
|
+
end
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
test 'should return temperature in fahrenheit by default' do
|
|
27
|
+
conditions.temperature.should == 24
|
|
28
|
+
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
test 'should return temperature in fahrenheit when specified' do
|
|
31
|
+
conditions.temperature(:f).should == 24
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
test 'should return temperature in celsius when specified' do
|
|
35
|
+
conditions.temperature(:c).should == -4
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'should raise ArgumentError if unknown unit specified for temperature' do
|
|
39
|
+
lambda { conditions.temperature(:kelvin) }.should raise_error(ArgumentError)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'should return relative humidity' do
|
|
43
|
+
conditions.relative_humidity.should == 52
|
|
44
|
+
end
|
|
33
45
|
|
|
34
46
|
test 'should return wind direction' do
|
|
35
47
|
conditions.wind_direction.should == 'Northwest'
|
data/test/test_forecast.rb
CHANGED
|
@@ -37,6 +37,18 @@ class TestForecast < NOAA::TestCase
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
4.times do |i|
|
|
41
|
+
should "return correct weather type code for day #{i}" do
|
|
42
|
+
forecast[i].weather_type_code.should == :ra
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
[80, 90, 20, 50].each_with_index do |probability, i|
|
|
47
|
+
should "return correct image URL for day #{i}" do
|
|
48
|
+
forecast[i].image_url.should == "http://www.nws.noaa.gov/weather/images/fcicons/ra#{probability}.jpg"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
40
52
|
[5, 94, 22, 50].each_with_index do |probability, i|
|
|
41
53
|
should "return correct daytime probability of precipitation for day #{i}" do
|
|
42
54
|
forecast[i].daytime_precipitation_probability.should == probability
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: outoftime-noaa
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mat Brown
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-12-
|
|
12
|
+
date: 2008-12-30 00:00:00 -08:00
|
|
13
13
|
default_executable: noaa-update-stations
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -105,7 +105,7 @@ homepage: http://github.com/outoftime/noaa
|
|
|
105
105
|
post_install_message: |-
|
|
106
106
|
Be sure to update the weather station list:
|
|
107
107
|
|
|
108
|
-
noaa-update-stations
|
|
108
|
+
sudo noaa-update-stations
|
|
109
109
|
|
|
110
110
|
This can be run at any time to update the stations, but you must run it once to initially populate the station list.
|
|
111
111
|
rdoc_options:
|