outoftime-noaa 0.1.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.
@@ -0,0 +1,129 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class TestCurrentConditions < NOAA::TestCase
4
+ XML_DOC = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', 'KVAY.xml'))
5
+
6
+ test 'should return observation time' do
7
+ conditions.observed_at.should == Time.parse('2008-12-23 10:54:00 -0500')
8
+ end
9
+
10
+ test 'should return weather description' do
11
+ conditions.weather_description.should == 'Fair'
12
+ end
13
+
14
+ test 'should return temperature in fahrenheit by default' do
15
+ conditions.temperature.should == 24
16
+ end
17
+
18
+ test 'should return temperature in fahrenheit when specified' do
19
+ conditions.temperature(:f).should == 24
20
+ end
21
+
22
+ test 'should return temperature in celsius when specified' do
23
+ conditions.temperature(:c).should == -4
24
+ end
25
+
26
+ test 'should raise ArgumentError if unknown unit specified for temperature' do
27
+ lambda { conditions.temperature(:kelvin) }.should raise_error(ArgumentError)
28
+ end
29
+
30
+ test 'should return relative humidity' do
31
+ conditions.relative_humidity.should == 52
32
+ end
33
+
34
+ test 'should return wind direction' do
35
+ conditions.wind_direction.should == 'Northwest'
36
+ end
37
+
38
+ test 'should return wind degrees' do
39
+ conditions.wind_degrees.should == 330
40
+ end
41
+
42
+ test 'should return wind speed in MPH' do
43
+ conditions.wind_speed.should == 3.45
44
+ end
45
+
46
+ test 'should return wind gust in MPH' do
47
+ conditions.wind_gust.should == 10.25
48
+ end
49
+
50
+ #TODO wind gust can be NA
51
+
52
+ test 'should return pressure in inches by default' do
53
+ conditions.pressure.should == 30.7
54
+ end
55
+
56
+ test 'should return pressure in inches when specified' do
57
+ conditions.pressure(:in).should == 30.7
58
+ end
59
+
60
+ test 'should return pressure in millibars when specified' do
61
+ conditions.pressure(:mb).should == 1039.5
62
+ end
63
+
64
+ test 'should throw ArgumentError when unrecognized pressure specified for pressure' do
65
+ lambda { conditions.pressure(:psi) }.should raise_error(ArgumentError)
66
+ end
67
+
68
+ test 'should return dew point in fahrenheit by default' do
69
+ conditions.dew_point.should == 9
70
+ end
71
+
72
+ test 'should return dew point in fahrenheit when specified' do
73
+ conditions.dew_point(:f).should == 9
74
+ end
75
+
76
+ test 'should return dew point in celsius when specified' do
77
+ conditions.dew_point(:c).should == -13
78
+ end
79
+
80
+ test 'should throw ArgumentError when unrecognized unit specified for dew point' do
81
+ lambda { conditions.dew_point(:kelvin) }.should raise_error(ArgumentError)
82
+ end
83
+
84
+ #TODO heat index can be NA
85
+
86
+ test 'should return heat index in fahrenheit by default' do
87
+ conditions.heat_index.should == 105
88
+ end
89
+
90
+ test 'should return heat index in fahrenheit when specified' do
91
+ conditions.heat_index(:f).should == 105
92
+ end
93
+
94
+ test 'should return heat index in celsius when specified' do
95
+ conditions.heat_index(:c).should == 41
96
+ end
97
+
98
+ test 'should throw ArgumentError when unrecognized unit specified for heat index' do
99
+ lambda { conditions.heat_index(:kelvin) }.should raise_error(ArgumentError)
100
+ end
101
+
102
+ #TODO wind chill can be NA
103
+
104
+ test 'should return wind chill in fahrenheit by default' do
105
+ conditions.wind_chill.should == 19
106
+ end
107
+
108
+ test 'should return wind chill in fahrenheit when specified' do
109
+ conditions.wind_chill(:f).should == 19
110
+ end
111
+
112
+ test 'should return wind chill in celsius when specified' do
113
+ conditions.wind_chill(:c).should == -7
114
+ end
115
+
116
+ test 'should throw ArgumentError when unrecognized unit specified for wind chill' do
117
+ lambda { conditions.wind_chill(:kelvin) }.should raise_error(ArgumentError)
118
+ end
119
+
120
+ test 'should return visibility in miles' do
121
+ conditions.visibility.should == 10.0
122
+ end
123
+
124
+ private
125
+
126
+ def conditions
127
+ @conditions ||= NOAA::CurrentConditions.from_xml(XML_DOC)
128
+ end
129
+ end
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class TestForecast < NOAA::TestCase
4
+ XML_DOC = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', '4-day.xml'))
5
+
6
+ should 'return number of days' do
7
+ forecast.length.should == 4
8
+ end
9
+
10
+ ['2008-12-23', '2008-12-24', '2008-12-25', '2008-12-26'].each_with_index do |date, i|
11
+ should "return correct start time for day #{i}" do
12
+ forecast[i].starts_at.should == Time.parse("#{date} 06:00:00 -05:00")
13
+ end
14
+ end
15
+
16
+ ['2008-12-24', '2008-12-25', '2008-12-26', '2008-12-27'].each_with_index do |date, i|
17
+ should "return correct end time for day #{i}" do
18
+ forecast[i].ends_at.should == Time.parse("#{date} 06:00:00 -05:00")
19
+ end
20
+ end
21
+
22
+ [32, 49, 43, 41].each_with_index do |temp, i|
23
+ should "return correct high for day #{i}" do
24
+ forecast[i].high.should == temp
25
+ end
26
+ end
27
+
28
+ [31, 41, 33, 39].each_with_index do |temp, i|
29
+ should "return correct low for day #{i}" do
30
+ forecast[i].low.should == temp
31
+ end
32
+ end
33
+
34
+ ['Rain', 'Rain', 'Slight Chance Rain', 'Chance Rain'].each_with_index do |summary, i|
35
+ should "return correct weather summary for day #{i}" do
36
+ forecast[i].weather_summary.should == summary
37
+ end
38
+ end
39
+
40
+ [5, 94, 22, 50].each_with_index do |probability, i|
41
+ should "return correct daytime probability of precipitation for day #{i}" do
42
+ forecast[i].daytime_precipitation_probability.should == probability
43
+ end
44
+ end
45
+
46
+ [77, 84, 19, 50].each_with_index do |probability, i|
47
+ should "return correct evening probability of precipitation for day #{i}" do
48
+ forecast[i].evening_precipitation_probability.should == probability
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def forecast
55
+ @forecast ||= NOAA::Forecast.from_xml(XML_DOC)
56
+ end
57
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ gem 'jeremymcanally-context', '>= 0.0.6'
3
+ gem 'jeremymcanally-matchy', '>= 0.0.1'
4
+ gem 'ruby-debug'
5
+
6
+
7
+ require 'context'
8
+ require 'matchy'
9
+ require 'ruby-debug'
10
+
11
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'noaa')
12
+
13
+ module NOAA
14
+ class TestCase < ::Test::Unit::TestCase
15
+ end
16
+ end
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class TestHttpService < NOAA::TestCase
4
+ before :each do
5
+ HTTP.reset
6
+ end
7
+
8
+ test 'should send properly-formed URL for current conditions' do
9
+ http_service.get_current_conditions('KNYC')
10
+ HTTP.requests.should == [URI.parse('http://www.weather.gov/xml/current_obs/KNYC.xml')]
11
+ end
12
+
13
+ test 'should return XML document for current conditions' do
14
+ http_service.get_current_conditions('KNYC').to_s.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test/>\n}
15
+ end
16
+
17
+ test 'should send properly-formed URL for forecast' do
18
+ http_service.get_forecast(4, 40.72, -73.99)
19
+ HTTP.requests.should == [URI.parse('http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=40.72&lon=-73.99&format=24+hourly&numDays=4')]
20
+ end
21
+
22
+ test 'should return XML document for forecast' do
23
+ http_service.get_forecast(4, 40.72, -73.99).to_s.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test/>\n}
24
+ end
25
+
26
+ test 'should send properly-formed URL for station list' do
27
+ http_service.get_station_list
28
+ HTTP.requests.should == [URI.parse('http://www.weather.gov/xml/current_obs/index.xml')]
29
+ end
30
+
31
+ test 'should return XML document for station list' do
32
+ http_service.get_station_list.to_s.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test/>\n}
33
+ end
34
+
35
+ private
36
+
37
+ def http_service
38
+ NOAA::HttpService.new(HTTP)
39
+ end
40
+
41
+ module HTTP
42
+ class <<self
43
+ def reset
44
+ requests.clear
45
+ end
46
+
47
+ def requests
48
+ @requests ||= []
49
+ end
50
+
51
+ def get(uri)
52
+ requests << uri
53
+ "<test/>"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,65 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class TestStation < NOAA::TestCase
4
+ before :all do
5
+ NOAA::Station.stations_file = File.join(File.dirname(__FILE__), 'data', 'stations.yml')
6
+ end
7
+
8
+ after :all do
9
+ NOAA::Station.stations_file = nil
10
+ end
11
+
12
+ test 'should load station by id' do
13
+ NOAA::Station.find('KNYC').id.should == 'KNYC'
14
+ end
15
+
16
+ test 'should find closest to coordinates' do
17
+ NOAA::Station.closest_to(GeoKit::LatLng.new(40.8, -73.96)).id.should == 'KNYC'
18
+ end
19
+
20
+ test 'should find closest to lat/lng' do
21
+ NOAA::Station.closest_to(40.8, -73.96).id.should == 'KNYC'
22
+ end
23
+
24
+ test 'should find closest to lat/lng passed as array' do
25
+ NOAA::Station.closest_to([40.8, -73.96]).id.should == 'KNYC'
26
+ end
27
+
28
+ test 'should throw ArgumentError if bad argument passed into #closest_to()' do
29
+ lambda { NOAA::Station.closest_to('hey') }.should raise_error(ArgumentError)
30
+ end
31
+
32
+ test 'should throw ArgumentError if more than two arguments passed into #closest_to()' do
33
+ lambda { NOAA::Station.closest_to(1, 2, 3) }.should raise_error(ArgumentError)
34
+ end
35
+
36
+ test 'should return name' do
37
+ station.name.should == 'New York City, Central Park'
38
+ end
39
+
40
+ test 'should return state' do
41
+ station.state.should == 'NY'
42
+ end
43
+
44
+ test 'should return XML URL' do
45
+ station.xml_url.should == 'http://weather.gov/xml/current_obs/KNYC.xml'
46
+ end
47
+
48
+ test 'should return latitude' do
49
+ station.latitude.should == 40.783
50
+ end
51
+
52
+ test 'should return longitude' do
53
+ station.longitude.should == -73.967
54
+ end
55
+
56
+ test 'should return coordinates' do
57
+ station.coordinates.should == GeoKit::LatLng.new(40.783, -73.967)
58
+ end
59
+
60
+ private
61
+
62
+ def station
63
+ NOAA::Station.find('KNYC')
64
+ end
65
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class TestStationWriter < NOAA::TestCase
4
+ XML_DOC = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', 'stations-abridged.xml'))
5
+
6
+ [40.66, 40.77, 40.783].each_with_index do |latitude, i|
7
+ test "should write latitude for station #{i}" do
8
+ yaml[i]['latitude'].should == latitude
9
+ end
10
+ end
11
+
12
+ [-73.78, -73.9, -73.967].each_with_index do |longitude, i|
13
+ test "should write longitude for station #{i}" do
14
+ yaml[i]['longitude'].should == longitude
15
+ end
16
+ end
17
+
18
+ ['KJFK', 'KLGA', 'KNYC'].each_with_index do |id, i|
19
+ test "should write id for station #{i}" do
20
+ yaml[i]['id'].should == id
21
+ end
22
+ end
23
+
24
+ ['New York/John F. Kennedy Intl Airport', 'New York, La Guardia Airport', 'New York City, Central Park'].each_with_index do |name, i|
25
+ test "should write name for station #{i}" do
26
+ yaml[i]['name'].should == name
27
+ end
28
+ end
29
+
30
+ (%w(NY) * 3).each_with_index do |state, i|
31
+ test "should write state for station #{i}" do
32
+ yaml[i]['state'].should == state
33
+ end
34
+ end
35
+
36
+ 3.times do |i|
37
+ test "should write XML URL for station #{i}" do
38
+ yaml[i]['xml_url'].should == "http://weather.gov/xml/current_obs/#{yaml[i]['id']}.xml"
39
+ end
40
+ end
41
+
42
+ def yaml
43
+ @yaml ||= begin
44
+ io = StringIO.new
45
+ NOAA::StationWriter.new(XML_DOC).write(io)
46
+ YAML.load(io.string)
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: outoftime-noaa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mat Brown
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-26 00:00:00 -08:00
13
+ default_executable: noaa-update-stations
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: libxml-ruby
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.7
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: andre-geokit
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.2.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: jeremymcanally-context
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.6
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: jeremymcanally-matchy
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.1
50
+ version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: ruby-debug
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: "0.10"
59
+ version:
60
+ description: Ruby API for National Oceanic and Atmospheric Administration weather data
61
+ email: mat@patch.com
62
+ executables:
63
+ - noaa-update-stations
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - lib/noaa/forecast.rb
68
+ - lib/noaa/http_service.rb
69
+ - lib/noaa/current_conditions.rb
70
+ - lib/noaa/station_writer.rb
71
+ - lib/noaa/station.rb
72
+ - lib/noaa/forecast_day.rb
73
+ - lib/noaa.rb
74
+ - bin/noaa-update-stations
75
+ - CHANGELOG
76
+ - README
77
+ files:
78
+ - lib/noaa/forecast.rb
79
+ - lib/noaa/http_service.rb
80
+ - lib/noaa/current_conditions.rb
81
+ - lib/noaa/station_writer.rb
82
+ - lib/noaa/station.rb
83
+ - lib/noaa/forecast_day.rb
84
+ - lib/noaa.rb
85
+ - Rakefile
86
+ - Manifest
87
+ - data/stations.yml
88
+ - bin/noaa-update-stations
89
+ - CHANGELOG
90
+ - test/test_station_writer.rb
91
+ - test/test_forecast.rb
92
+ - test/data/stations.xml
93
+ - test/data/stations-abridged.xml
94
+ - test/data/stations.yml
95
+ - test/data/KVAY.xml
96
+ - test/data/4-day.xml
97
+ - test/test_helper.rb
98
+ - test/test_station.rb
99
+ - test/test_http_service.rb
100
+ - test/test_current_conditions.rb
101
+ - README
102
+ - noaa.gemspec
103
+ has_rdoc: true
104
+ homepage: http://github.com/outoftime/noaa
105
+ post_install_message: |-
106
+ Be sure to update the weather station list:
107
+
108
+ noaa-update-stations
109
+
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
+ rdoc_options:
112
+ - --line-numbers
113
+ - --inline-source
114
+ - --title
115
+ - Noaa
116
+ - --main
117
+ - README
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: "0"
125
+ version:
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: "1.2"
131
+ version:
132
+ requirements: []
133
+
134
+ rubyforge_project: noaa
135
+ rubygems_version: 1.2.0
136
+ signing_key:
137
+ specification_version: 2
138
+ summary: Ruby API for National Oceanic and Atmospheric Administration weather data
139
+ test_files:
140
+ - test/test_station_writer.rb
141
+ - test/test_forecast.rb
142
+ - test/test_helper.rb
143
+ - test/test_station.rb
144
+ - test/test_http_service.rb
145
+ - test/test_current_conditions.rb