barometer 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.rdoc +78 -70
  2. data/VERSION.yml +2 -2
  3. data/bin/barometer +100 -37
  4. data/lib/barometer.rb +12 -8
  5. data/lib/barometer/base.rb +48 -20
  6. data/lib/barometer/data.rb +5 -1
  7. data/lib/barometer/data/current.rb +23 -15
  8. data/lib/barometer/data/distance.rb +15 -5
  9. data/lib/barometer/data/forecast.rb +23 -5
  10. data/lib/barometer/data/geo.rb +16 -54
  11. data/lib/barometer/data/local_datetime.rb +137 -0
  12. data/lib/barometer/data/local_time.rb +134 -0
  13. data/lib/barometer/data/location.rb +6 -1
  14. data/lib/barometer/data/measurement.rb +71 -42
  15. data/lib/barometer/data/night.rb +69 -0
  16. data/lib/barometer/data/pressure.rb +15 -5
  17. data/lib/barometer/data/speed.rb +16 -5
  18. data/lib/barometer/data/sun.rb +8 -20
  19. data/lib/barometer/data/temperature.rb +22 -9
  20. data/lib/barometer/data/units.rb +10 -19
  21. data/lib/barometer/data/zone.rb +135 -9
  22. data/lib/barometer/formats.rb +12 -0
  23. data/lib/barometer/formats/coordinates.rb +42 -0
  24. data/lib/barometer/formats/format.rb +46 -0
  25. data/lib/barometer/formats/geocode.rb +51 -0
  26. data/lib/barometer/formats/icao.rb +37 -0
  27. data/lib/barometer/formats/postalcode.rb +22 -0
  28. data/lib/barometer/formats/short_zipcode.rb +17 -0
  29. data/lib/barometer/formats/weather_id.rb +107 -0
  30. data/lib/barometer/formats/zipcode.rb +31 -0
  31. data/lib/barometer/query.rb +61 -232
  32. data/lib/barometer/services.rb +14 -4
  33. data/lib/barometer/translations/icao_country_codes.yml +9 -0
  34. data/lib/barometer/translations/weather_country_codes.yml +17 -0
  35. data/lib/barometer/weather.rb +51 -30
  36. data/lib/barometer/{services → weather_services}/google.rb +23 -26
  37. data/lib/barometer/weather_services/noaa.rb +6 -0
  38. data/lib/barometer/{services → weather_services}/service.rb +101 -92
  39. data/lib/barometer/weather_services/weather_bug.rb +6 -0
  40. data/lib/barometer/weather_services/weather_dot_com.rb +261 -0
  41. data/lib/barometer/{services → weather_services}/wunderground.rb +58 -76
  42. data/lib/barometer/{services → weather_services}/yahoo.rb +91 -121
  43. data/lib/barometer/web_services/geocode.rb +33 -0
  44. data/lib/barometer/web_services/weather_id.rb +37 -0
  45. data/lib/barometer/web_services/web_service.rb +32 -0
  46. data/lib/demometer/demometer.rb +31 -4
  47. data/lib/demometer/views/forecast.erb +20 -0
  48. data/lib/demometer/views/index.erb +10 -3
  49. data/lib/demometer/views/measurement.erb +8 -3
  50. data/lib/demometer/views/readme.erb +63 -24
  51. data/spec/barometer_spec.rb +18 -36
  52. data/spec/{data_current_spec.rb → data/current_spec.rb} +73 -49
  53. data/spec/{data_distance_spec.rb → data/distance_spec.rb} +30 -30
  54. data/spec/{data_forecast_spec.rb → data/forecast_spec.rb} +57 -15
  55. data/spec/data/geo_spec.rb +91 -0
  56. data/spec/data/local_datetime_spec.rb +269 -0
  57. data/spec/data/local_time_spec.rb +239 -0
  58. data/spec/{data_location_spec.rb → data/location_spec.rb} +12 -1
  59. data/spec/{data_measurement_spec.rb → data/measurement_spec.rb} +135 -66
  60. data/spec/data/night_measurement_spec.rb +136 -0
  61. data/spec/{data_pressure_spec.rb → data/pressure_spec.rb} +29 -29
  62. data/spec/{data_speed_spec.rb → data/speed_spec.rb} +30 -30
  63. data/spec/data/sun_spec.rb +49 -0
  64. data/spec/{data_temperature_spec.rb → data/temperature_spec.rb} +44 -44
  65. data/spec/{units_spec.rb → data/units_spec.rb} +6 -6
  66. data/spec/{data_zone_spec.rb → data/zone_spec.rb} +15 -15
  67. data/spec/fixtures/formats/weather_id/90210.xml +1 -0
  68. data/spec/fixtures/formats/weather_id/atlanta.xml +1 -0
  69. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +1 -0
  70. data/spec/fixtures/formats/weather_id/new_york.xml +1 -0
  71. data/spec/fixtures/{geocode_40_73.xml → geocode/40_73.xml} +0 -0
  72. data/spec/fixtures/{geocode_90210.xml → geocode/90210.xml} +0 -0
  73. data/spec/fixtures/{geocode_T5B4M9.xml → geocode/T5B4M9.xml} +0 -0
  74. data/spec/fixtures/geocode/atlanta.xml +1 -0
  75. data/spec/fixtures/{geocode_calgary_ab.xml → geocode/calgary_ab.xml} +0 -0
  76. data/spec/fixtures/{geocode_ksfo.xml → geocode/ksfo.xml} +0 -0
  77. data/spec/fixtures/{geocode_newyork_ny.xml → geocode/newyork_ny.xml} +0 -0
  78. data/spec/fixtures/{google_calgary_ab.xml → services/google/calgary_ab.xml} +0 -0
  79. data/spec/fixtures/services/weather_dot_com/90210.xml +1 -0
  80. data/spec/fixtures/{current_calgary_ab.xml → services/wunderground/current_calgary_ab.xml} +0 -0
  81. data/spec/fixtures/{forecast_calgary_ab.xml → services/wunderground/forecast_calgary_ab.xml} +0 -0
  82. data/spec/fixtures/{yahoo_90210.xml → services/yahoo/90210.xml} +0 -0
  83. data/spec/formats/coordinates_spec.rb +158 -0
  84. data/spec/formats/format_spec.rb +73 -0
  85. data/spec/formats/geocode_spec.rb +179 -0
  86. data/spec/formats/icao_spec.rb +61 -0
  87. data/spec/formats/postalcode_spec.rb +59 -0
  88. data/spec/formats/short_zipcode_spec.rb +53 -0
  89. data/spec/formats/weather_id_spec.rb +191 -0
  90. data/spec/formats/zipcode_spec.rb +111 -0
  91. data/spec/query_spec.rb +261 -288
  92. data/spec/spec_helper.rb +128 -4
  93. data/spec/{service_google_spec.rb → weather_services/google_spec.rb} +46 -46
  94. data/spec/weather_services/services_spec.rb +1118 -0
  95. data/spec/weather_services/weather_dot_com_spec.rb +327 -0
  96. data/spec/weather_services/wunderground_spec.rb +332 -0
  97. data/spec/{service_yahoo_spec.rb → weather_services/yahoo_spec.rb} +65 -81
  98. data/spec/weather_spec.rb +73 -61
  99. data/spec/web_services/geocode_spec.rb +45 -0
  100. data/spec/web_services/web_services_spec.rb +26 -0
  101. metadata +88 -36
  102. data/lib/barometer/services/noaa.rb +0 -6
  103. data/lib/barometer/services/weather_bug.rb +0 -6
  104. data/lib/barometer/services/weather_dot_com.rb +0 -6
  105. data/spec/data_geo_spec.rb +0 -94
  106. data/spec/data_sun_spec.rb +0 -76
  107. data/spec/service_wunderground_spec.rb +0 -330
  108. data/spec/services_spec.rb +0 -1106
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Query::Geocode" do
4
+
5
+ before(:each) do
6
+ @zipcode = "90210"
7
+ end
8
+
9
+ describe "and the class methods" do
10
+
11
+ describe "fetch," do
12
+
13
+ it "requires a Query object" do
14
+ lambda { Barometer::WebService::Geocode.fetch }.should raise_error(ArgumentError)
15
+ lambda { Barometer::WebService::Geocode.fetch("invalid") }.should raise_error(ArgumentError)
16
+ query = Barometer::Query.new(@zipcode)
17
+ query.is_a?(Barometer::Query).should be_true
18
+ lambda { Barometer::WebService::Geocode.fetch(query) }.should_not raise_error(ArgumentError)
19
+ end
20
+
21
+ it "detects the key" do
22
+ query = Barometer::Query.new(@zipcode)
23
+ Barometer.google_geocode_key = nil
24
+ Barometer::WebService::Geocode.fetch(query).should be_nil
25
+ Barometer.google_geocode_key = KEY
26
+ Barometer::WebService::Geocode.fetch(query).should_not be_nil
27
+ end
28
+
29
+ it "returns a Geo object" do
30
+ query = Barometer::Query.new(@zipcode)
31
+ Barometer::WebService::Geocode.fetch(query).is_a?(Data::Geo).should be_true
32
+ end
33
+
34
+ end
35
+
36
+ it "detects the Google Geocode Key" do
37
+ Barometer.google_geocode_key = nil
38
+ Barometer::WebService::Geocode.send("_has_geocode_key?").should be_false
39
+ Barometer.google_geocode_key = KEY
40
+ Barometer::WebService::Geocode.send("_has_geocode_key?").should be_true
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Web Services" do
4
+
5
+ describe "and the class method" do
6
+
7
+ describe "source" do
8
+
9
+ it "stubs fetch" do
10
+ lambda { Barometer::WebService.fetch }.should raise_error(NotImplementedError)
11
+ end
12
+
13
+ it "detects a Query object" do
14
+ invalid = 1
15
+ Barometer::WebService.send("_is_a_query?").should be_false
16
+ Barometer::WebService.send("_is_a_query?", invalid).should be_false
17
+ valid = Barometer::Query.new
18
+ valid.is_a?(Barometer::Query).should be_true
19
+ Barometer::WebService.send("_is_a_query?", valid).should be_true
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barometer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark G
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-03 00:00:00 -06:00
12
+ date: 2009-05-07 00:00:00 -06:00
13
13
  default_executable: barometer
14
14
  dependencies: []
15
15
 
@@ -33,8 +33,11 @@ files:
33
33
  - lib/barometer/data/distance.rb
34
34
  - lib/barometer/data/forecast.rb
35
35
  - lib/barometer/data/geo.rb
36
+ - lib/barometer/data/local_datetime.rb
37
+ - lib/barometer/data/local_time.rb
36
38
  - lib/barometer/data/location.rb
37
39
  - lib/barometer/data/measurement.rb
40
+ - lib/barometer/data/night.rb
38
41
  - lib/barometer/data/pressure.rb
39
42
  - lib/barometer/data/speed.rb
40
43
  - lib/barometer/data/sun.rb
@@ -45,17 +48,34 @@ files:
45
48
  - lib/barometer/extensions
46
49
  - lib/barometer/extensions/graticule.rb
47
50
  - lib/barometer/extensions/httparty.rb
51
+ - lib/barometer/formats
52
+ - lib/barometer/formats/coordinates.rb
53
+ - lib/barometer/formats/format.rb
54
+ - lib/barometer/formats/geocode.rb
55
+ - lib/barometer/formats/icao.rb
56
+ - lib/barometer/formats/postalcode.rb
57
+ - lib/barometer/formats/short_zipcode.rb
58
+ - lib/barometer/formats/weather_id.rb
59
+ - lib/barometer/formats/zipcode.rb
60
+ - lib/barometer/formats.rb
48
61
  - lib/barometer/query.rb
49
- - lib/barometer/services
50
- - lib/barometer/services/google.rb
51
- - lib/barometer/services/noaa.rb
52
- - lib/barometer/services/service.rb
53
- - lib/barometer/services/weather_bug.rb
54
- - lib/barometer/services/weather_dot_com.rb
55
- - lib/barometer/services/wunderground.rb
56
- - lib/barometer/services/yahoo.rb
57
62
  - lib/barometer/services.rb
63
+ - lib/barometer/translations
64
+ - lib/barometer/translations/icao_country_codes.yml
65
+ - lib/barometer/translations/weather_country_codes.yml
58
66
  - lib/barometer/weather.rb
67
+ - lib/barometer/weather_services
68
+ - lib/barometer/weather_services/google.rb
69
+ - lib/barometer/weather_services/noaa.rb
70
+ - lib/barometer/weather_services/service.rb
71
+ - lib/barometer/weather_services/weather_bug.rb
72
+ - lib/barometer/weather_services/weather_dot_com.rb
73
+ - lib/barometer/weather_services/wunderground.rb
74
+ - lib/barometer/weather_services/yahoo.rb
75
+ - lib/barometer/web_services
76
+ - lib/barometer/web_services/geocode.rb
77
+ - lib/barometer/web_services/weather_id.rb
78
+ - lib/barometer/web_services/web_service.rb
59
79
  - lib/barometer.rb
60
80
  - lib/demometer
61
81
  - lib/demometer/demometer.rb
@@ -72,36 +92,68 @@ files:
72
92
  - lib/demometer/views/measurement.erb
73
93
  - lib/demometer/views/readme.erb
74
94
  - spec/barometer_spec.rb
75
- - spec/data_current_spec.rb
76
- - spec/data_distance_spec.rb
77
- - spec/data_forecast_spec.rb
78
- - spec/data_geo_spec.rb
79
- - spec/data_location_spec.rb
80
- - spec/data_measurement_spec.rb
81
- - spec/data_pressure_spec.rb
82
- - spec/data_speed_spec.rb
83
- - spec/data_sun_spec.rb
84
- - spec/data_temperature_spec.rb
85
- - spec/data_zone_spec.rb
95
+ - spec/data
96
+ - spec/data/current_spec.rb
97
+ - spec/data/distance_spec.rb
98
+ - spec/data/forecast_spec.rb
99
+ - spec/data/geo_spec.rb
100
+ - spec/data/local_datetime_spec.rb
101
+ - spec/data/local_time_spec.rb
102
+ - spec/data/location_spec.rb
103
+ - spec/data/measurement_spec.rb
104
+ - spec/data/night_measurement_spec.rb
105
+ - spec/data/pressure_spec.rb
106
+ - spec/data/speed_spec.rb
107
+ - spec/data/sun_spec.rb
108
+ - spec/data/temperature_spec.rb
109
+ - spec/data/units_spec.rb
110
+ - spec/data/zone_spec.rb
86
111
  - spec/fixtures
87
- - spec/fixtures/current_calgary_ab.xml
88
- - spec/fixtures/forecast_calgary_ab.xml
89
- - spec/fixtures/geocode_40_73.xml
90
- - spec/fixtures/geocode_90210.xml
91
- - spec/fixtures/geocode_calgary_ab.xml
92
- - spec/fixtures/geocode_ksfo.xml
93
- - spec/fixtures/geocode_newyork_ny.xml
94
- - spec/fixtures/geocode_T5B4M9.xml
95
- - spec/fixtures/google_calgary_ab.xml
96
- - spec/fixtures/yahoo_90210.xml
112
+ - spec/fixtures/formats
113
+ - spec/fixtures/formats/weather_id
114
+ - spec/fixtures/formats/weather_id/90210.xml
115
+ - spec/fixtures/formats/weather_id/atlanta.xml
116
+ - spec/fixtures/formats/weather_id/from_USGA0028.xml
117
+ - spec/fixtures/formats/weather_id/new_york.xml
118
+ - spec/fixtures/geocode
119
+ - spec/fixtures/geocode/40_73.xml
120
+ - spec/fixtures/geocode/90210.xml
121
+ - spec/fixtures/geocode/atlanta.xml
122
+ - spec/fixtures/geocode/calgary_ab.xml
123
+ - spec/fixtures/geocode/ksfo.xml
124
+ - spec/fixtures/geocode/newyork_ny.xml
125
+ - spec/fixtures/geocode/T5B4M9.xml
126
+ - spec/fixtures/services
127
+ - spec/fixtures/services/google
128
+ - spec/fixtures/services/google/calgary_ab.xml
129
+ - spec/fixtures/services/weather_dot_com
130
+ - spec/fixtures/services/weather_dot_com/90210.xml
131
+ - spec/fixtures/services/wunderground
132
+ - spec/fixtures/services/wunderground/current_calgary_ab.xml
133
+ - spec/fixtures/services/wunderground/forecast_calgary_ab.xml
134
+ - spec/fixtures/services/yahoo
135
+ - spec/fixtures/services/yahoo/90210.xml
136
+ - spec/formats
137
+ - spec/formats/coordinates_spec.rb
138
+ - spec/formats/format_spec.rb
139
+ - spec/formats/geocode_spec.rb
140
+ - spec/formats/icao_spec.rb
141
+ - spec/formats/postalcode_spec.rb
142
+ - spec/formats/short_zipcode_spec.rb
143
+ - spec/formats/weather_id_spec.rb
144
+ - spec/formats/zipcode_spec.rb
97
145
  - spec/query_spec.rb
98
- - spec/service_google_spec.rb
99
- - spec/service_wunderground_spec.rb
100
- - spec/service_yahoo_spec.rb
101
- - spec/services_spec.rb
102
146
  - spec/spec_helper.rb
103
- - spec/units_spec.rb
147
+ - spec/weather_services
148
+ - spec/weather_services/google_spec.rb
149
+ - spec/weather_services/services_spec.rb
150
+ - spec/weather_services/weather_dot_com_spec.rb
151
+ - spec/weather_services/wunderground_spec.rb
152
+ - spec/weather_services/yahoo_spec.rb
104
153
  - spec/weather_spec.rb
154
+ - spec/web_services
155
+ - spec/web_services/geocode_spec.rb
156
+ - spec/web_services/web_services_spec.rb
105
157
  - LICENSE
106
158
  has_rdoc: true
107
159
  homepage: http://github.com/attack/barometer
@@ -1,6 +0,0 @@
1
- module Barometer
2
-
3
- class Noaa < Service
4
- end
5
-
6
- end
@@ -1,6 +0,0 @@
1
- module Barometer
2
-
3
- class WeatherBug < Service
4
- end
5
-
6
- end
@@ -1,6 +0,0 @@
1
- module Barometer
2
-
3
- class WeatherDotCom < Service
4
- end
5
-
6
- end
@@ -1,94 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'rubygems'
4
- require 'graticule'
5
-
6
- describe "Geo" do
7
-
8
- describe "when initialized" do
9
-
10
- before(:each) do
11
- @geo = Barometer::Geo.new
12
- end
13
-
14
- it "responds to latitude" do
15
- @geo.latitude.should be_nil
16
- end
17
-
18
- it "responds to longitude" do
19
- @geo.longitude.should be_nil
20
- end
21
-
22
- it "responds to country_code" do
23
- @geo.country_code.should be_nil
24
- end
25
-
26
- it "responds to locality" do
27
- @geo.locality.should be_nil
28
- end
29
-
30
- it "responds to region" do
31
- @geo.region.should be_nil
32
- end
33
-
34
- it "responds to country" do
35
- @geo.country.should be_nil
36
- end
37
-
38
- it "responds to address" do
39
- @geo.address.should be_nil
40
- end
41
-
42
- it "responds to coordinates" do
43
- @geo.longitude = "99.99"
44
- @geo.latitude = "88.88"
45
- @geo.coordinates.should == [@geo.latitude, @geo.longitude].join(',')
46
- end
47
-
48
- it "requires Graticule::Location or Hash object" do
49
- location = Graticule::Location.new
50
- lambda { Barometer::Geo.new(1) }.should raise_error(ArgumentError)
51
- Barometer::Geo.new(location)
52
- lambda { Barometer::Geo.new(location) }.should_not raise_error(ArgumentError)
53
- lambda { Barometer::Geo.new(Hash.new) }.should_not raise_error(ArgumentError)
54
- end
55
-
56
- it "returns a Barometer::Geo object" do
57
- location = Graticule::Location.new
58
- geo = Barometer::Geo.new(location)
59
- geo.is_a?(Barometer::Geo).should be_true
60
- end
61
-
62
- end
63
-
64
- describe "when converting" do
65
-
66
- before(:each) do
67
- @geo = Barometer::Geo.new
68
- end
69
-
70
- describe "from Graticule" do
71
-
72
- it "requires Graticule::Location object (or nil)" do
73
- location = Graticule::Location.new
74
- lambda { @geo.build_from_graticule(1) }.should raise_error(ArgumentError)
75
- lambda { @geo.build_from_graticule }.should_not raise_error(ArgumentError)
76
- lambda { @geo.build_from_graticule(location) }.should_not raise_error(ArgumentError)
77
- end
78
-
79
- end
80
-
81
- describe "from HTTParty" do
82
-
83
- it "accepts HTTParty::Response object" do
84
- location = Hash.new
85
- lambda { @geo.build_from_httparty(1) }.should raise_error(ArgumentError)
86
- lambda { @geo.build_from_httparty }.should_not raise_error(ArgumentError)
87
- lambda { @geo.build_from_httparty(location) }.should_not raise_error(ArgumentError)
88
- end
89
-
90
- end
91
-
92
- end
93
-
94
- end
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Sun" do
4
-
5
- describe "when initialized" do
6
-
7
- before(:each) do
8
- @sun = Barometer::Sun.new
9
- @time_rise = Time.now
10
- @time_set = Time.now + (60*60*8)
11
- end
12
-
13
- it "responds to rise" do
14
- @sun.respond_to?("rise").should be_true
15
- end
16
-
17
- it "responds to set" do
18
- @sun.respond_to?("set").should be_true
19
- end
20
-
21
- it "sets sunrise" do
22
- sun = Barometer::Sun.new(@time_rise,@time_set)
23
- sun.rise.should == @time_rise
24
- end
25
-
26
- it "sets sunset" do
27
- sun = Barometer::Sun.new(@time_rise,@time_set)
28
- sun.set.should == @time_set
29
- end
30
-
31
- it "requires Time for sunrise" do
32
- lambda { Barometer::Sun.new("",@time_set) }.should raise_error(ArgumentError)
33
- lambda { Barometer::Sun.new(@time_rise,@time_set) }.should_not raise_error(ArgumentError)
34
- end
35
-
36
- it "requires Time for sunset" do
37
- lambda { Barometer::Sun.new(@time_rise,"") }.should raise_error(ArgumentError)
38
- lambda { Barometer::Sun.new(@time_rise,@time_set) }.should_not raise_error(ArgumentError)
39
- end
40
-
41
- it "responds to nil?" do
42
- @sun.nil?.should be_true
43
- sun = Barometer::Sun.new(@time_rise, @time_set)
44
- sun.nil?.should be_false
45
- end
46
-
47
- end
48
-
49
- describe "when adjusting times" do
50
-
51
- before(:each) do
52
- @time_rise = Time.now
53
- @time_set = Time.now + (60*60*8)
54
- @sun = Barometer::Sun.new(@time_rise, @time_set)
55
- end
56
-
57
- it "requires a Barometer::Sun object" do
58
- lambda { Barometer::Sun.add_days!("invalid") }.should raise_error(ArgumentError)
59
- lambda { Barometer::Sun.add_days!(@sun) }.should_not raise_error(ArgumentError)
60
- end
61
-
62
- it "requires a Fixnum object" do
63
- lambda { Barometer::Sun.add_days!(@sun,1.1) }.should raise_error(ArgumentError)
64
- lambda { Barometer::Sun.add_days!(@sun,1) }.should_not raise_error(ArgumentError)
65
- end
66
-
67
- it "adds X days to both sun_rise and sun_set" do
68
- days_to_add = 2
69
- new_sun = Barometer::Sun.add_days!(@sun, days_to_add)
70
- new_sun.rise.should == @sun.rise + (60*60*24*days_to_add)
71
- new_sun.set.should == @sun.set + (60*60*24*days_to_add)
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,330 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Wunderground" do
4
-
5
- before(:each) do
6
- @accepted_formats = [:zipcode, :postalcode, :icao, :coordinates, :geocode]
7
- @base_uri = "http://api.wunderground.com/auto/wui/geo"
8
- end
9
-
10
- describe "the class methods" do
11
-
12
- it "defines accepted_formats" do
13
- Barometer::Wunderground.accepted_formats.should == @accepted_formats
14
- end
15
-
16
- it "defines get_current" do
17
- Barometer::Wunderground.respond_to?("get_current").should be_true
18
- end
19
-
20
- it "defines get_forecast" do
21
- Barometer::Wunderground.respond_to?("get_forecast").should be_true
22
- end
23
-
24
- end
25
-
26
- describe "building the current data" do
27
-
28
- it "defines the build method" do
29
- Barometer::Wunderground.respond_to?("build_current").should be_true
30
- end
31
-
32
- it "requires Hash input" do
33
- lambda { Barometer::Wunderground.build_current }.should raise_error(ArgumentError)
34
- lambda { Barometer::Wunderground.build_current({}) }.should_not raise_error(ArgumentError)
35
- end
36
-
37
- it "returns Barometer::CurrentMeasurement object" do
38
- current = Barometer::Wunderground.build_current({})
39
- current.is_a?(Barometer::CurrentMeasurement).should be_true
40
- end
41
-
42
- end
43
-
44
- describe "building the forecast data" do
45
-
46
- it "defines the build method" do
47
- Barometer::Wunderground.respond_to?("build_forecast").should be_true
48
- end
49
-
50
- it "requires Hash input" do
51
- lambda { Barometer::Wunderground.build_forecast }.should raise_error(ArgumentError)
52
- lambda { Barometer::Wunderground.build_forecast({}) }.should_not raise_error(ArgumentError)
53
- end
54
-
55
- it "returns Array object" do
56
- current = Barometer::Wunderground.build_forecast({})
57
- current.is_a?(Array).should be_true
58
- end
59
-
60
- end
61
-
62
- describe "building the station data" do
63
-
64
- it "defines the build method" do
65
- Barometer::Wunderground.respond_to?("build_station").should be_true
66
- end
67
-
68
- it "requires Hash input" do
69
- lambda { Barometer::Wunderground.build_station }.should raise_error(ArgumentError)
70
- lambda { Barometer::Wunderground.build_station({}) }.should_not raise_error(ArgumentError)
71
- end
72
-
73
- it "returns Barometer::Location object" do
74
- station = Barometer::Wunderground.build_station({})
75
- station.is_a?(Barometer::Location).should be_true
76
- end
77
-
78
- end
79
-
80
- describe "building the location data" do
81
-
82
- it "defines the build method" do
83
- Barometer::Wunderground.respond_to?("build_location").should be_true
84
- end
85
-
86
- it "requires Hash input" do
87
- lambda { Barometer::Wunderground.build_location }.should raise_error(ArgumentError)
88
- lambda { Barometer::Wunderground.build_location({}) }.should_not raise_error(ArgumentError)
89
- end
90
-
91
- it "returns Barometer::Location object" do
92
- location = Barometer::Wunderground.build_location({})
93
- location.is_a?(Barometer::Location).should be_true
94
- end
95
-
96
- end
97
-
98
- describe "building the timezone" do
99
-
100
- it "defines the build method" do
101
- Barometer::Wunderground.respond_to?("build_timezone").should be_true
102
- end
103
-
104
- it "requires Hash input" do
105
- lambda { Barometer::Wunderground.build_timezone }.should raise_error(ArgumentError)
106
- lambda { Barometer::Wunderground.build_timezone({}) }.should_not raise_error(ArgumentError)
107
- end
108
-
109
- end
110
-
111
- describe "building the sun data" do
112
-
113
- before(:each) do
114
- @zone = Barometer::Zone.new("Europe/Paris")
115
- end
116
-
117
- it "defines the build method" do
118
- Barometer::Wunderground.respond_to?("build_sun").should be_true
119
- end
120
-
121
- it "requires Hash input" do
122
- lambda { Barometer::Wunderground.build_sun }.should raise_error(ArgumentError)
123
- lambda { Barometer::Wunderground.build_sun({},@zone) }.should_not raise_error(ArgumentError)
124
- end
125
-
126
- it "requires Barometer::Zone input" do
127
- lambda { Barometer::Wunderground.build_sun({}) }.should raise_error(ArgumentError)
128
- lambda { Barometer::Wunderground.build_sun({}, "invalid") }.should raise_error(ArgumentError)
129
- lambda { Barometer::Wunderground.build_sun({},@zone) }.should_not raise_error(ArgumentError)
130
- end
131
-
132
- it "returns Barometer::Sun object" do
133
- sun = Barometer::Wunderground.build_sun({},@zone)
134
- sun.is_a?(Barometer::Sun).should be_true
135
- end
136
-
137
- end
138
-
139
- describe "when measuring" do
140
-
141
- before(:each) do
142
- @query = Barometer::Query.new("Calgary,AB")
143
- @query.preferred = "Calgary,AB"
144
- @measurement = Barometer::Measurement.new
145
-
146
- FakeWeb.register_uri(:get,
147
- "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(@query.preferred)}",
148
- :string => File.read(File.join(File.dirname(__FILE__),
149
- 'fixtures',
150
- 'current_calgary_ab.xml')
151
- )
152
- )
153
- FakeWeb.register_uri(:get,
154
- "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(@query.preferred)}",
155
- :string => File.read(File.join(File.dirname(__FILE__),
156
- 'fixtures',
157
- 'forecast_calgary_ab.xml')
158
- )
159
- )
160
- end
161
-
162
- describe "all" do
163
-
164
- it "responds to _measure" do
165
- Barometer::Wunderground.respond_to?("_measure").should be_true
166
- end
167
-
168
- it "requires a Barometer::Measurement object" do
169
- lambda { Barometer::Wunderground._measure(nil, @query) }.should raise_error(ArgumentError)
170
- lambda { Barometer::Wunderground._measure("invlaid", @query) }.should raise_error(ArgumentError)
171
-
172
- lambda { Barometer::Wunderground._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
173
- end
174
-
175
- it "requires a Barometer::Query query" do
176
- lambda { Barometer::Wunderground._measure }.should raise_error(ArgumentError)
177
- lambda { Barometer::Wunderground._measure(@measurement, 1) }.should raise_error(ArgumentError)
178
-
179
- lambda { Barometer::Wunderground._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
180
- end
181
-
182
- it "returns a Barometer::Measurement object" do
183
- result = Barometer::Wunderground._measure(@measurement, @query)
184
- result.is_a?(Barometer::Measurement).should be_true
185
- result.current.is_a?(Barometer::CurrentMeasurement).should be_true
186
- result.forecast.is_a?(Array).should be_true
187
-
188
- result.source.should == :wunderground
189
- end
190
-
191
- end
192
-
193
- end
194
-
195
- describe "when answering the simple questions," do
196
-
197
- before(:each) do
198
- @measurement = Barometer::Measurement.new
199
- end
200
-
201
- describe "currently_wet_by_icon?" do
202
-
203
- before(:each) do
204
- @measurement.current = Barometer::CurrentMeasurement.new
205
- end
206
-
207
- it "returns true if matching icon code" do
208
- @measurement.current.icon = "rain"
209
- @measurement.current.icon?.should be_true
210
- Barometer::Wunderground.currently_wet_by_icon?(@measurement.current).should be_true
211
- end
212
-
213
- it "returns false if NO matching icon code" do
214
- @measurement.current.icon = "sunny"
215
- @measurement.current.icon?.should be_true
216
- Barometer::Wunderground.currently_wet_by_icon?(@measurement.current).should be_false
217
- end
218
-
219
- end
220
-
221
- describe "forecasted_wet_by_icon?" do
222
-
223
- before(:each) do
224
- @measurement.forecast = [Barometer::ForecastMeasurement.new]
225
- @measurement.forecast.first.date = Date.today
226
- @measurement.forecast.size.should == 1
227
- end
228
-
229
- it "returns true if matching icon code" do
230
- @measurement.forecast.first.icon = "rain"
231
- @measurement.forecast.first.icon?.should be_true
232
- Barometer::Wunderground.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
233
- end
234
-
235
- it "returns false if NO matching icon code" do
236
- @measurement.forecast.first.icon = "sunny"
237
- @measurement.forecast.first.icon?.should be_true
238
- Barometer::Wunderground.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
239
- end
240
-
241
- end
242
-
243
- describe "currently_sunny_by_icon?" do
244
-
245
- before(:each) do
246
- @measurement.current = Barometer::CurrentMeasurement.new
247
- end
248
-
249
- it "returns true if matching icon code" do
250
- @measurement.current.icon = "sunny"
251
- @measurement.current.icon?.should be_true
252
- Barometer::Wunderground.currently_sunny_by_icon?(@measurement.current).should be_true
253
- end
254
-
255
- it "returns false if NO matching icon code" do
256
- @measurement.current.icon = "rain"
257
- @measurement.current.icon?.should be_true
258
- Barometer::Wunderground.currently_sunny_by_icon?(@measurement.current).should be_false
259
- end
260
-
261
- end
262
-
263
- describe "forecasted_sunny_by_icon?" do
264
-
265
- before(:each) do
266
- @measurement.forecast = [Barometer::ForecastMeasurement.new]
267
- @measurement.forecast.first.date = Date.today
268
- @measurement.forecast.size.should == 1
269
- end
270
-
271
- it "returns true if matching icon code" do
272
- @measurement.forecast.first.icon = "sunny"
273
- @measurement.forecast.first.icon?.should be_true
274
- Barometer::Wunderground.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
275
- end
276
-
277
- it "returns false if NO matching icon code" do
278
- @measurement.forecast.first.icon = "rain"
279
- @measurement.forecast.first.icon?.should be_true
280
- Barometer::Wunderground.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
281
- end
282
-
283
- end
284
-
285
- end
286
-
287
- describe "overall data correctness" do
288
-
289
- before(:each) do
290
- @query = Barometer::Query.new("Calgary,AB")
291
- @query.preferred = "Calgary,AB"
292
- @measurement = Barometer::Measurement.new
293
-
294
- FakeWeb.register_uri(:get,
295
- "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(@query.preferred)}",
296
- :string => File.read(File.join(File.dirname(__FILE__),
297
- 'fixtures',
298
- 'current_calgary_ab.xml')
299
- )
300
- )
301
- FakeWeb.register_uri(:get,
302
- "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(@query.preferred)}",
303
- :string => File.read(File.join(File.dirname(__FILE__),
304
- 'fixtures',
305
- 'forecast_calgary_ab.xml')
306
- )
307
- )
308
- end
309
-
310
- # TODO: complete this
311
- it "should correctly build the data" do
312
- result = Barometer::Wunderground._measure(@measurement, @query)
313
-
314
- # build timezone
315
- @measurement.timezone.timezone.should == "America/Edmonton"
316
-
317
- time = Time.local(2009, 4, 23, 18, 00, 0)
318
- rise = Time.local(time.year, time.month, time.day, 6, 23)
319
- set = Time.local(time.year, time.month, time.day, 20, 45)
320
- sun_rise = @measurement.timezone.tz.local_to_utc(rise)
321
- sun_set = @measurement.timezone.tz.local_to_utc(set)
322
-
323
- # build current
324
- @measurement.current.sun.rise.should == sun_rise
325
- @measurement.current.sun.set.should == sun_set
326
- end
327
-
328
- end
329
-
330
- end