barometer 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/LICENSE +1 -1
  4. data/{README.rdoc → README.md} +124 -110
  5. data/Rakefile +1 -21
  6. data/TODO +8 -9
  7. data/barometer.gemspec +20 -19
  8. data/bin/barometer +36 -83
  9. data/lib/barometer.rb +13 -11
  10. data/lib/barometer/base.rb +10 -10
  11. data/lib/barometer/data.rb +1 -1
  12. data/lib/barometer/data/distance.rb +25 -25
  13. data/lib/barometer/data/geo.rb +9 -9
  14. data/lib/barometer/data/local_datetime.rb +24 -20
  15. data/lib/barometer/data/local_time.rb +13 -13
  16. data/lib/barometer/data/location.rb +6 -6
  17. data/lib/barometer/data/pressure.rb +24 -24
  18. data/lib/barometer/data/speed.rb +28 -28
  19. data/lib/barometer/data/sun.rb +7 -7
  20. data/lib/barometer/data/temperature.rb +29 -29
  21. data/lib/barometer/data/units.rb +9 -9
  22. data/lib/barometer/data/zone.rb +19 -19
  23. data/lib/barometer/formats.rb +1 -1
  24. data/lib/barometer/formats/coordinates.rb +7 -7
  25. data/lib/barometer/formats/format.rb +6 -6
  26. data/lib/barometer/formats/geocode.rb +5 -5
  27. data/lib/barometer/formats/icao.rb +6 -6
  28. data/lib/barometer/formats/postalcode.rb +3 -3
  29. data/lib/barometer/formats/short_zipcode.rb +2 -2
  30. data/lib/barometer/formats/weather_id.rb +10 -10
  31. data/lib/barometer/formats/woe_id.rb +20 -20
  32. data/lib/barometer/formats/zipcode.rb +3 -3
  33. data/lib/barometer/key_file_parser.rb +20 -0
  34. data/lib/barometer/measurements/measurement.rb +32 -32
  35. data/lib/barometer/measurements/result.rb +39 -39
  36. data/lib/barometer/measurements/result_array.rb +12 -12
  37. data/lib/barometer/query.rb +15 -15
  38. data/lib/barometer/services.rb +3 -3
  39. data/lib/barometer/translations/icao_country_codes.yml +20 -20
  40. data/lib/barometer/translations/weather_country_codes.yml +1 -1
  41. data/lib/barometer/translations/zone_codes.yml +2 -2
  42. data/lib/barometer/version.rb +3 -0
  43. data/lib/barometer/weather.rb +27 -27
  44. data/lib/barometer/weather_services/noaa.rb +314 -3
  45. data/lib/barometer/weather_services/service.rb +32 -30
  46. data/lib/barometer/weather_services/weather_bug.rb +35 -33
  47. data/lib/barometer/weather_services/wunderground.rb +31 -29
  48. data/lib/barometer/weather_services/yahoo.rb +36 -35
  49. data/lib/barometer/web_services/geocode.rb +5 -7
  50. data/lib/barometer/web_services/noaa_station_id.rb +53 -0
  51. data/lib/barometer/web_services/placemaker.rb +11 -13
  52. data/lib/barometer/web_services/timezone.rb +5 -7
  53. data/lib/barometer/web_services/weather_id.rb +4 -6
  54. data/lib/barometer/web_services/web_service.rb +4 -4
  55. data/spec/barometer_spec.rb +25 -27
  56. data/spec/cassettes/Barometer.json +1 -0
  57. data/spec/cassettes/Query.json +1 -0
  58. data/spec/cassettes/Query_Format_Coordinates.json +1 -0
  59. data/spec/cassettes/Query_Format_Geocode.json +1 -0
  60. data/spec/cassettes/Query_Format_WeatherID.json +1 -0
  61. data/spec/cassettes/Query_Format_WoeID.json +1 -0
  62. data/spec/cassettes/WeatherService.json +1 -0
  63. data/spec/cassettes/WeatherService_Noaa.json +1 -0
  64. data/spec/cassettes/WeatherService_WeatherBug.json +1 -0
  65. data/spec/cassettes/WeatherService_Wunderground.json +1 -0
  66. data/spec/cassettes/WeatherService_Yahoo.json +1 -0
  67. data/spec/cassettes/WebService_Geocode.json +1 -0
  68. data/spec/cassettes/WebService_NoaaStation.json +1 -0
  69. data/spec/data/distance_spec.rb +60 -60
  70. data/spec/data/geo_spec.rb +23 -23
  71. data/spec/data/local_datetime_spec.rb +44 -44
  72. data/spec/data/local_time_spec.rb +47 -47
  73. data/spec/data/location_spec.rb +16 -16
  74. data/spec/data/pressure_spec.rb +61 -61
  75. data/spec/data/speed_spec.rb +69 -69
  76. data/spec/data/sun_spec.rb +25 -25
  77. data/spec/data/temperature_spec.rb +68 -68
  78. data/spec/data/units_spec.rb +21 -21
  79. data/spec/data/zone_spec.rb +35 -35
  80. data/spec/formats/coordinates_spec.rb +27 -27
  81. data/spec/formats/format_spec.rb +17 -25
  82. data/spec/formats/geocode_spec.rb +23 -31
  83. data/spec/formats/icao_spec.rb +26 -32
  84. data/spec/formats/postalcode_spec.rb +22 -28
  85. data/spec/formats/short_zipcode_spec.rb +20 -26
  86. data/spec/formats/weather_id_spec.rb +57 -67
  87. data/spec/formats/woe_id_spec.rb +59 -59
  88. data/spec/formats/zipcode_spec.rb +39 -47
  89. data/spec/key_file_parser_spec.rb +28 -0
  90. data/spec/measurements/measurement_spec.rb +79 -133
  91. data/spec/measurements/result_array_spec.rb +23 -38
  92. data/spec/measurements/result_spec.rb +100 -128
  93. data/spec/query_spec.rb +83 -100
  94. data/spec/spec_helper.rb +24 -6
  95. data/spec/weather_services/noaa_spec.rb +179 -0
  96. data/spec/weather_services/services_spec.rb +28 -36
  97. data/spec/weather_services/weather_bug_spec.rb +57 -77
  98. data/spec/weather_services/wunderground_spec.rb +36 -65
  99. data/spec/weather_services/yahoo_spec.rb +38 -60
  100. data/spec/weather_spec.rb +79 -79
  101. data/spec/web_services/geocode_spec.rb +7 -11
  102. data/spec/web_services/noaa_station_id_spec.rb +33 -0
  103. data/spec/web_services/placemaker_spec.rb +7 -12
  104. data/spec/web_services/web_services_spec.rb +3 -9
  105. metadata +214 -163
  106. data/VERSION.yml +0 -5
  107. data/lib/barometer/weather_services/google.rb +0 -142
  108. data/lib/barometer/weather_services/weather_dot_com.rb +0 -279
  109. data/spec/fakeweb_helper.rb +0 -179
  110. data/spec/fixtures/formats/weather_id/90210.xml +0 -7
  111. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +0 -3
  112. data/spec/fixtures/formats/weather_id/ksfo.xml +0 -1
  113. data/spec/fixtures/formats/weather_id/manhattan.xml +0 -7
  114. data/spec/fixtures/formats/weather_id/new_york.xml +0 -1
  115. data/spec/fixtures/formats/weather_id/the_hills.xml +0 -1
  116. data/spec/fixtures/geocode/40_73_v3.json +0 -497
  117. data/spec/fixtures/geocode/90210_v3.json +0 -63
  118. data/spec/fixtures/geocode/T5B4M9_v3.json +0 -68
  119. data/spec/fixtures/geocode/atlanta_v3.json +0 -58
  120. data/spec/fixtures/geocode/calgary_ab_v3.json +0 -58
  121. data/spec/fixtures/geocode/ksfo_v3.json +0 -73
  122. data/spec/fixtures/geocode/newyork_ny_v3.json +0 -58
  123. data/spec/fixtures/services/google/calgary_ab.xml +0 -1
  124. data/spec/fixtures/services/placemaker/T5B4M9.xml +0 -65
  125. data/spec/fixtures/services/placemaker/atlanta.xml +0 -65
  126. data/spec/fixtures/services/placemaker/coords.xml +0 -65
  127. data/spec/fixtures/services/placemaker/ksfo.xml +0 -65
  128. data/spec/fixtures/services/placemaker/new_york.xml +0 -65
  129. data/spec/fixtures/services/placemaker/the_hills.xml +0 -65
  130. data/spec/fixtures/services/placemaker/w615702.xml +0 -47
  131. data/spec/fixtures/services/weather_bug/90210_current.xml +0 -93
  132. data/spec/fixtures/services/weather_bug/90210_forecast.xml +0 -76
  133. data/spec/fixtures/services/weather_dot_com/90210.xml +0 -1
  134. data/spec/fixtures/services/wunderground/current_calgary_ab.xml +0 -9
  135. data/spec/fixtures/services/wunderground/forecast_calgary_ab.xml +0 -13
  136. data/spec/fixtures/services/yahoo/90210.xml +0 -3
  137. data/spec/weather_services/google_spec.rb +0 -181
  138. data/spec/weather_services/weather_dot_com_spec.rb +0 -224
@@ -1,7 +1,16 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require "addressable/uri"
2
3
 
3
- describe "Query::WoeID" do
4
-
4
+ params_in_body = lambda do |request_1, request_2|
5
+ a1 = Addressable::URI.parse("?#{request_1.body}")
6
+ a2 = Addressable::URI.parse("?#{request_2.body}")
7
+ a1.query_values == a2.query_values
8
+ end
9
+
10
+ describe Barometer::Query::Format::WoeID, :vcr => {
11
+ :match_requests_on => [:method, :uri, params_in_body],
12
+ :cassette_name => "Query::Format::WoeID"
13
+ } do
5
14
  before(:each) do
6
15
  @short_zipcode = "90210"
7
16
  @zipcode = @short_zipcode
@@ -13,81 +22,77 @@ describe "Query::WoeID" do
13
22
  @icao = "KSFO"
14
23
  @woe_id = "615702"
15
24
  end
16
-
25
+
17
26
  describe "and class methods" do
18
-
19
27
  it "returns a format" do
20
28
  Barometer::Query::Format::WoeID.format.should == :woe_id
21
29
  end
22
-
30
+
23
31
  it "returns a country" do
24
32
  Barometer::Query::Format::WoeID.country_code.should be_nil
25
33
  end
26
-
34
+
27
35
  it "returns a regex" do
28
36
  Barometer::Query::Format::WoeID.regex.should_not be_nil
29
37
  Barometer::Query::Format::WoeID.regex.is_a?(Regexp).should be_true
30
38
  end
31
-
39
+
32
40
  it "returns the convertable_formats" do
33
- Query::Format::WoeID.convertable_formats.should_not be_nil
34
- Query::Format::WoeID.convertable_formats.is_a?(Array).should be_true
35
- Query::Format::WoeID.convertable_formats.include?(:short_zipcode).should be_true
36
- Query::Format::WoeID.convertable_formats.include?(:zipcode).should be_true
37
- Query::Format::WoeID.convertable_formats.include?(:postalcode).should be_true
38
- Query::Format::WoeID.convertable_formats.include?(:weather_id).should be_true
39
- Query::Format::WoeID.convertable_formats.include?(:coordinates).should be_true
40
- Query::Format::WoeID.convertable_formats.include?(:icao).should be_true
41
- Query::Format::WoeID.convertable_formats.include?(:geocode).should be_true
41
+ Barometer::Query::Format::WoeID.convertable_formats.should_not be_nil
42
+ Barometer::Query::Format::WoeID.convertable_formats.is_a?(Array).should be_true
43
+ Barometer::Query::Format::WoeID.convertable_formats.include?(:short_zipcode).should be_true
44
+ Barometer::Query::Format::WoeID.convertable_formats.include?(:zipcode).should be_true
45
+ Barometer::Query::Format::WoeID.convertable_formats.include?(:postalcode).should be_true
46
+ Barometer::Query::Format::WoeID.convertable_formats.include?(:weather_id).should be_true
47
+ Barometer::Query::Format::WoeID.convertable_formats.include?(:coordinates).should be_true
48
+ Barometer::Query::Format::WoeID.convertable_formats.include?(:icao).should be_true
49
+ Barometer::Query::Format::WoeID.convertable_formats.include?(:geocode).should be_true
42
50
  end
43
-
51
+
44
52
  describe "is?," do
45
-
46
53
  it "recognizes a valid 4 digit code format" do
47
54
  @query = "8775"
48
55
  Barometer::Query::Format::WoeID.is?(@query).should be_true
49
56
  end
50
-
57
+
51
58
  it "recognizes a valid 6 digit code format" do
52
59
  @query = "615702"
53
60
  Barometer::Query::Format::WoeID.is?(@query).should be_true
54
61
  end
55
-
62
+
56
63
  it "recognizes a valid 7 digit code format" do
57
64
  @query = "2459115"
58
65
  Barometer::Query::Format::WoeID.is?(@query).should be_true
59
66
  end
60
-
67
+
61
68
  it "recognizes a valid 5 digit code with a prepended 'w'" do
62
69
  @query = "w90210"
63
70
  Barometer::Query::Format::WoeID.is?(@query).should be_true
64
71
  end
65
-
72
+
66
73
  it "does not recognize a zip code" do
67
74
  @query = "90210"
68
75
  Barometer::Query::Format::WoeID.is?(@query).should be_false
69
76
  end
70
-
77
+
71
78
  it "recognizes non-valid format" do
72
79
  @query = "USGA0028"
73
80
  Barometer::Query::Format::WoeID.is?(@query).should be_false
74
81
  end
75
-
76
82
  end
77
-
83
+
78
84
  it "converts the query" do
79
85
  query_no_conversion = "2459115"
80
86
  query = Barometer::Query.new(query_no_conversion)
81
87
  query.q.should == query_no_conversion
82
-
88
+
83
89
  query_with_conversion = "w90210"
84
90
  query = Barometer::Query.new(query_with_conversion)
85
91
  query.q.should_not == query_with_conversion
86
92
  query.q.should == "90210"
87
93
  end
88
-
94
+
89
95
  describe "when reversing lookup" do
90
-
91
96
  it "requires a Barometer::Query object" do
92
97
  lambda { Barometer::Query::Format::WoeID.reverse }.should raise_error(ArgumentError)
93
98
  lambda { Barometer::Query::Format::WoeID.reverse("invalid") }.should raise_error(ArgumentError)
@@ -95,12 +100,12 @@ describe "Query::WoeID" do
95
100
  query.is_a?(Barometer::Query).should be_true
96
101
  lambda { Barometer::Query::Format::WoeID.reverse(original_query) }.should_not raise_error(ArgumentError)
97
102
  end
98
-
103
+
99
104
  it "returns a Barometer::Query" do
100
105
  query = Barometer::Query.new(@woe_id)
101
106
  Barometer::Query::Format::WoeID.reverse(query).is_a?(Barometer::Query).should be_true
102
107
  end
103
-
108
+
104
109
  it "reverses a valid woe_id (US)" do
105
110
  query = Barometer::Query.new(@woe_id)
106
111
  new_query = Barometer::Query::Format::WoeID.reverse(query)
@@ -109,103 +114,98 @@ describe "Query::WoeID" do
109
114
  new_query.format.should == :geocode
110
115
  new_query.geo.should be_nil
111
116
  end
112
-
117
+
113
118
  it "doesn't reverse an invalid weather_id" do
114
119
  query = Barometer::Query.new(@zipcode)
115
120
  Barometer::Query::Format::WoeID.reverse(query).should be_nil
116
121
  end
117
-
118
122
  end
119
-
123
+
120
124
  describe "when converting using 'to'," do
121
-
122
125
  it "requires a Barometer::Query object" do
123
- lambda { Query::Format::WoeID.to }.should raise_error(ArgumentError)
124
- lambda { Query::Format::WoeID.to("invalid") }.should raise_error(ArgumentError)
126
+ lambda { Barometer::Query::Format::WoeID.to }.should raise_error(ArgumentError)
127
+ lambda { Barometer::Query::Format::WoeID.to("invalid") }.should raise_error(ArgumentError)
125
128
  query = Barometer::Query.new(@woe_id)
126
129
  query.is_a?(Barometer::Query).should be_true
127
- lambda { Query::Format::WoeID.to(original_query) }.should_not raise_error(ArgumentError)
130
+ lambda { Barometer::Query::Format::WoeID.to(original_query) }.should_not raise_error(ArgumentError)
128
131
  end
129
-
132
+
130
133
  it "returns a Barometer::Query" do
131
134
  query = Barometer::Query.new(@geocode)
132
- Query::Format::WoeID.to(query).is_a?(Barometer::Query).should be_true
135
+ Barometer::Query::Format::WoeID.to(query).is_a?(Barometer::Query).should be_true
133
136
  end
134
-
137
+
135
138
  it "converts from short_zipcode" do
136
139
  query = Barometer::Query.new(@short_zipcode)
137
140
  query.format.should == :short_zipcode
138
- new_query = Query::Format::WoeID.to(query)
141
+ new_query = Barometer::Query::Format::WoeID.to(query)
139
142
  new_query.q.should == "2363796"
140
143
  new_query.country_code.should == "US"
141
144
  new_query.format.should == :woe_id
142
145
  new_query.geo.should_not be_nil
143
146
  end
144
-
147
+
145
148
  it "converts from zipcode" do
146
149
  query = Barometer::Query.new(@zipcode)
147
150
  query.format = :zipcode
148
151
  query.format.should == :zipcode
149
- new_query = Query::Format::WoeID.to(query)
152
+ new_query = Barometer::Query::Format::WoeID.to(query)
150
153
  new_query.q.should == "2363796"
151
154
  new_query.country_code.should == "US"
152
155
  new_query.format.should == :woe_id
153
156
  new_query.geo.should_not be_nil
154
157
  end
155
-
158
+
156
159
  it "converts from postal code" do
157
160
  query = Barometer::Query.new(@postal_code)
158
161
  query.format = :postalcode
159
162
  query.format.should == :postalcode
160
- new_query = Query::Format::WoeID.to(query)
163
+ new_query = Barometer::Query::Format::WoeID.to(query)
161
164
  new_query.q.should == "8676"
162
165
  new_query.country_code.should == "CA"
163
166
  new_query.format.should == :woe_id
164
167
  new_query.geo.should be_nil
165
168
  end
166
-
169
+
167
170
  it "converts from coordinates" do
168
171
  query = Barometer::Query.new(@coordinates)
169
172
  query.format.should == :coordinates
170
- new_query = Query::Format::WoeID.to(query)
171
- new_query.q.should == "2459115"
173
+ new_query = Barometer::Query::Format::WoeID.to(query)
174
+ new_query.q.should == "12589342"
172
175
  new_query.country_code.should be_nil
173
176
  new_query.format.should == :woe_id
174
177
  new_query.geo.should be_nil
175
178
  end
176
-
179
+
177
180
  it "converts from geocode" do
178
181
  query = Barometer::Query.new(@geocode)
179
182
  query.format.should == :geocode
180
- new_query = Query::Format::WoeID.to(query)
183
+ new_query = Barometer::Query::Format::WoeID.to(query)
181
184
  new_query.q.should == "2459115"
182
185
  new_query.country_code.should be_nil
183
186
  new_query.format.should == :woe_id
184
187
  new_query.geo.should be_nil
185
188
  end
186
-
189
+
187
190
  it "converts from weather_id" do
188
191
  query = Barometer::Query.new(@weather_id)
189
192
  query.format.should == :weather_id
190
- new_query = Query::Format::WoeID.to(query)
193
+ new_query = Barometer::Query::Format::WoeID.to(query)
191
194
  new_query.q.should == "2357024"
192
195
  new_query.country_code.should be_nil
193
196
  new_query.format.should == :woe_id
194
197
  new_query.geo.should be_nil
195
198
  end
196
-
199
+
197
200
  it "converts from icao" do
198
201
  query = Barometer::Query.new(@icao)
199
202
  query.format.should == :icao
200
- new_query = Query::Format::WoeID.to(query)
201
- new_query.q.should == "2451206"
203
+ new_query = Barometer::Query::Format::WoeID.to(query)
204
+ new_query.q.should == "2487956"
202
205
  new_query.country_code.should == "US"
203
206
  new_query.format.should == :woe_id
204
207
  new_query.geo.should_not be_nil
205
208
  end
206
-
207
209
  end
208
-
209
210
  end
210
-
211
- end
211
+ end
@@ -1,7 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Query::Zipcode" do
4
-
3
+ describe Barometer::Query::Format::Zipcode do
5
4
  before(:each) do
6
5
  @short_zipcode = "90210"
7
6
  @zipcode = @short_zipcode
@@ -12,100 +11,93 @@ describe "Query::Zipcode" do
12
11
  @geocode = "New York, NY"
13
12
  @icao = "KSFO"
14
13
  end
15
-
14
+
16
15
  describe "and class methods" do
17
-
18
16
  it "returns a format" do
19
- Query::Format::Zipcode.format.should == :zipcode
17
+ Barometer::Query::Format::Zipcode.format.should == :zipcode
20
18
  end
21
-
19
+
22
20
  it "returns a country" do
23
- Query::Format::Zipcode.country_code.should == "US"
24
- Query::Format::Zipcode.country_code("ignored").should == "US"
21
+ Barometer::Query::Format::Zipcode.country_code.should == "US"
22
+ Barometer::Query::Format::Zipcode.country_code("ignored").should == "US"
25
23
  end
26
-
24
+
27
25
  it "returns a regex" do
28
- Query::Format::Zipcode.regex.should_not be_nil
29
- Query::Format::Zipcode.regex.is_a?(Regexp).should be_true
26
+ Barometer::Query::Format::Zipcode.regex.should_not be_nil
27
+ Barometer::Query::Format::Zipcode.regex.is_a?(Regexp).should be_true
30
28
  end
31
-
29
+
32
30
  it "returns the convertable_formats" do
33
- Query::Format::Zipcode.convertable_formats.should_not be_nil
34
- Query::Format::Zipcode.convertable_formats.is_a?(Array).should be_true
35
- Query::Format::Zipcode.convertable_formats.include?(:short_zipcode).should be_true
31
+ Barometer::Query::Format::Zipcode.convertable_formats.should_not be_nil
32
+ Barometer::Query::Format::Zipcode.convertable_formats.is_a?(Array).should be_true
33
+ Barometer::Query::Format::Zipcode.convertable_formats.include?(:short_zipcode).should be_true
36
34
  end
37
-
35
+
38
36
  describe "is?," do
39
-
40
37
  before(:each) do
41
38
  @valid = "90210-5555"
42
39
  @invalid = "invalid"
43
40
  end
44
-
41
+
45
42
  it "recognizes a valid format" do
46
- Query::Format::Zipcode.is?(@valid).should be_true
43
+ Barometer::Query::Format::Zipcode.is?(@valid).should be_true
47
44
  end
48
-
45
+
49
46
  it "recognizes non-valid format" do
50
- Query::Format::Zipcode.is?(@invalid).should be_false
47
+ Barometer::Query::Format::Zipcode.is?(@invalid).should be_false
51
48
  end
52
-
53
49
  end
54
-
50
+
55
51
  describe "when converting using 'to'," do
56
-
57
52
  it "requires a Barometer::Query object" do
58
- lambda { Query::Format::Zipcode.to }.should raise_error(ArgumentError)
59
- lambda { Query::Format::Zipcode.to("invalid") }.should raise_error(ArgumentError)
53
+ lambda { Barometer::Query::Format::Zipcode.to }.should raise_error(ArgumentError)
54
+ lambda { Barometer::Query::Format::Zipcode.to("invalid") }.should raise_error(ArgumentError)
60
55
  query = Barometer::Query.new(@zipcode)
61
56
  query.is_a?(Barometer::Query).should be_true
62
- lambda { Query::Format::Zipcode.to(original_query) }.should_not raise_error(ArgumentError)
57
+ lambda { Barometer::Query::Format::Zipcode.to(original_query) }.should_not raise_error(ArgumentError)
63
58
  end
64
-
59
+
65
60
  it "returns a Barometer::Query" do
66
61
  query = Barometer::Query.new(@short_zipcode)
67
- Query::Format::Zipcode.to(query).is_a?(Barometer::Query).should be_true
62
+ Barometer::Query::Format::Zipcode.to(query).is_a?(Barometer::Query).should be_true
68
63
  end
69
-
64
+
70
65
  it "converts from short_zipcode" do
71
66
  query = Barometer::Query.new(@short_zipcode)
72
67
  query.format.should == :short_zipcode
73
- new_query = Query::Format::Zipcode.to(query)
68
+ new_query = Barometer::Query::Format::Zipcode.to(query)
74
69
  new_query.q.should == @short_zipcode
75
70
  new_query.format.should == :zipcode
76
71
  new_query.country_code.should == "US"
77
72
  new_query.geo.should be_nil
78
73
  end
79
-
74
+
80
75
  it "returns nil for other formats" do
81
76
  query = Barometer::Query.new(@zipcode)
82
77
  query.format = :zipcode
83
78
  query.format.should == :zipcode
84
- Query::Format::Zipcode.to(query).should be_nil
85
-
79
+ Barometer::Query::Format::Zipcode.to(query).should be_nil
80
+
86
81
  query = Barometer::Query.new(@weather_id)
87
82
  query.format.should == :weather_id
88
- Query::Format::Zipcode.to(query).should be_nil
89
-
83
+ Barometer::Query::Format::Zipcode.to(query).should be_nil
84
+
90
85
  query = Barometer::Query.new(@postal_code)
91
86
  query.format.should == :postalcode
92
- Query::Format::Zipcode.to(query).should be_nil
93
-
87
+ Barometer::Query::Format::Zipcode.to(query).should be_nil
88
+
94
89
  query = Barometer::Query.new(@coordinates)
95
90
  query.format.should == :coordinates
96
- Query::Format::Zipcode.to(query).should be_nil
97
-
91
+ Barometer::Query::Format::Zipcode.to(query).should be_nil
92
+
98
93
  query = Barometer::Query.new(@geocode)
99
94
  query.format.should == :geocode
100
- Query::Format::Zipcode.to(query).should be_nil
101
-
95
+ Barometer::Query::Format::Zipcode.to(query).should be_nil
96
+
102
97
  query = Barometer::Query.new(@icao)
103
98
  query.format.should == :icao
104
- Query::Format::Zipcode.to(query).should be_nil
99
+ Barometer::Query::Format::Zipcode.to(query).should be_nil
105
100
  end
106
-
107
101
  end
108
-
109
102
  end
110
-
111
- end
103
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Barometer::KeyFileParser do
4
+ include FakeFS::SpecHelpers
5
+
6
+ it "returns the the KEY for the given path" do
7
+ FakeFS do
8
+ FileUtils.mkdir("~")
9
+ File.open(Barometer::KEY_FILE, 'w') {|f| f << "\weather_bug:\n code: ABC123" }
10
+ Barometer::KeyFileParser.find(:weather_bug, :code).should == "ABC123"
11
+ end
12
+ end
13
+
14
+ it "returns nil when the key does not exist" do
15
+ FakeFS do
16
+ FileUtils.mkdir("~")
17
+ File.open(Barometer::KEY_FILE, 'w') {|f| f << "\weather_bug:\n" }
18
+ Barometer::KeyFileParser.find(:weather_bug, :code).should be_nil
19
+ end
20
+ end
21
+
22
+ it "returns nil when the file does not exist" do
23
+ FakeFS do
24
+ FileUtils.mkdir("~")
25
+ Barometer::KeyFileParser.find(:weather_bug, :code).should be_nil
26
+ end
27
+ end
28
+ end
@@ -1,199 +1,189 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Measurement" do
4
-
3
+ describe Barometer::Measurement do
5
4
  describe "when initialized" do
6
-
7
5
  before(:each) do
8
6
  @measurement = Barometer::Measurement.new
9
7
  end
10
-
8
+
11
9
  it "responds to source" do
12
10
  @measurement.source.should be_nil
13
11
  end
14
-
12
+
15
13
  it "stores the source" do
16
14
  source = :wunderground
17
15
  measurement = Barometer::Measurement.new(source)
18
16
  measurement.source.should_not be_nil
19
17
  measurement.source.should == source
20
18
  end
21
-
19
+
22
20
  it "responds to utc_time_stamp" do
23
21
  @measurement.utc_time_stamp.should be_nil
24
22
  end
25
-
23
+
26
24
  it "responds to current" do
27
25
  @measurement.current.should be_nil
28
26
  end
29
-
27
+
30
28
  it "responds to forecast (and defaults to an empty Array)" do
31
29
  @measurement.forecast.should be_nil
32
30
  end
33
-
31
+
34
32
  it "responds to timezone" do
35
33
  @measurement.timezone.should be_nil
36
34
  end
37
-
35
+
38
36
  it "responds to station" do
39
37
  @measurement.station.should be_nil
40
38
  end
41
-
39
+
42
40
  it "responds to location" do
43
41
  @measurement.location.should be_nil
44
42
  end
45
-
43
+
46
44
  it "responds to success" do
47
45
  @measurement.success.should be_false
48
46
  end
49
-
47
+
50
48
  it "responds to current?" do
51
49
  @measurement.current?.should be_true
52
50
  end
53
-
51
+
54
52
  it "responds to metric" do
55
53
  @measurement.metric.should be_true
56
54
  end
57
-
55
+
58
56
  it "responds to weight" do
59
57
  @measurement.weight.should == 1
60
58
  end
61
-
59
+
62
60
  it "responds to links" do
63
61
  @measurement.links.should == {}
64
62
  end
65
-
63
+
66
64
  it "responds to measured_at" do
67
65
  @measurement.measured_at.should be_nil
68
66
  end
69
-
70
- # it "responds to measured_for" do
71
- # @measurement.links.should == {}
72
- # end
73
-
74
67
  end
75
-
68
+
76
69
  describe "when writing data" do
77
-
78
70
  before(:each) do
79
71
  @measurement = Barometer::Measurement.new
80
72
  end
81
-
73
+
82
74
  it "only accepts Symbol for source" do
83
75
  invalid_data = 1
84
76
  invalid_data.class.should_not == Symbol
85
77
  lambda { @measurement.source = invalid_data }.should raise_error(ArgumentError)
86
-
78
+
87
79
  valid_data = :valid
88
80
  valid_data.class.should == Symbol
89
81
  lambda { @measurement.source = valid_data }.should_not raise_error(ArgumentError)
90
82
  end
91
-
83
+
92
84
  it "only accepts Time for utc_time_stamp" do
93
85
  invalid_data = 1
94
86
  invalid_data.class.should_not == Time
95
87
  lambda { @measurement.utc_time_stamp = invalid_data }.should raise_error(ArgumentError)
96
-
88
+
97
89
  valid_data = Time.now.utc
98
90
  valid_data.class.should == Time
99
91
  lambda { @measurement.utc_time_stamp = valid_data }.should_not raise_error(ArgumentError)
100
92
  end
101
-
93
+
102
94
  it "only accepts Measurement::Result for current" do
103
95
  invalid_data = "invalid"
104
96
  invalid_data.class.should_not == Barometer::Measurement::Result
105
97
  lambda { @measurement.current = invalid_data }.should raise_error(ArgumentError)
106
-
98
+
107
99
  valid_data = Barometer::Measurement::Result.new
108
100
  valid_data.class.should == Barometer::Measurement::Result
109
101
  lambda { @measurement.current = valid_data }.should_not raise_error(ArgumentError)
110
102
  end
111
-
103
+
112
104
  it "only accepts Data::ResultArray for forecast" do
113
105
  invalid_data = 1
114
106
  invalid_data.class.should_not == Barometer::Measurement::ResultArray
115
107
  lambda { @measurement.forecast = invalid_data }.should raise_error(ArgumentError)
116
-
108
+
117
109
  valid_data = Barometer::Measurement::ResultArray.new
118
110
  valid_data.class.should == Barometer::Measurement::ResultArray
119
111
  lambda { @measurement.forecast = valid_data }.should_not raise_error(ArgumentError)
120
112
  end
121
-
113
+
122
114
  it "only accepts Data::Zone for timezone" do
123
115
  invalid_data = 1
124
116
  invalid_data.class.should_not == Data::Zone
125
117
  lambda { @measurement.timezone = invalid_data }.should raise_error(ArgumentError)
126
-
118
+
127
119
  valid_data = Data::Zone.new("Europe/Paris")
128
120
  valid_data.class.should == Data::Zone
129
121
  lambda { @measurement.timezone = valid_data }.should_not raise_error(ArgumentError)
130
122
  end
131
-
123
+
132
124
  it "only accepts Data::Location for station" do
133
125
  invalid_data = 1
134
126
  invalid_data.class.should_not == Data::Location
135
127
  lambda { @measurement.station = invalid_data }.should raise_error(ArgumentError)
136
-
128
+
137
129
  valid_data = Data::Location.new
138
130
  valid_data.class.should == Data::Location
139
131
  lambda { @measurement.station = valid_data }.should_not raise_error(ArgumentError)
140
132
  end
141
-
133
+
142
134
  it "only accepts Data::Location for location" do
143
135
  invalid_data = 1
144
136
  invalid_data.class.should_not == Data::Location
145
137
  lambda { @measurement.location = invalid_data }.should raise_error(ArgumentError)
146
-
138
+
147
139
  valid_data = Data::Location.new
148
140
  valid_data.class.should == Data::Location
149
141
  lambda { @measurement.location = valid_data }.should_not raise_error(ArgumentError)
150
142
  end
151
-
143
+
152
144
  it "only accepts Fixnum for weight" do
153
145
  invalid_data = "test"
154
146
  invalid_data.class.should_not == Fixnum
155
147
  lambda { @measurement.weight = invalid_data }.should raise_error(ArgumentError)
156
-
148
+
157
149
  valid_data = 1
158
150
  valid_data.class.should == Fixnum
159
151
  lambda { @measurement.weight = valid_data }.should_not raise_error(ArgumentError)
160
152
  end
161
-
153
+
162
154
  it "only accepts Array for links" do
163
155
  invalid_data = 1
164
156
  invalid_data.class.should_not == Hash
165
157
  lambda { @measurement.links = invalid_data }.should raise_error(ArgumentError)
166
-
158
+
167
159
  valid_data = {1 => nil}
168
160
  valid_data.class.should == Hash
169
161
  lambda { @measurement.links = valid_data }.should_not raise_error(ArgumentError)
170
162
  end
171
-
163
+
172
164
  it "only accepts Data::LocalTime for measured_at" do
173
165
  invalid_data = 1
174
166
  invalid_data.class.should_not == Data::LocalTime
175
167
  lambda { @measurement.measured_at = invalid_data }.should raise_error(ArgumentError)
176
-
168
+
177
169
  valid_data = Data::LocalTime.new
178
170
  valid_data.class.should == Data::LocalTime
179
171
  lambda { @measurement.measured_at = valid_data }.should_not raise_error(ArgumentError)
180
172
  end
181
-
182
173
  end
183
-
174
+
184
175
  describe "and the helpers" do
185
-
186
176
  before(:each) do
187
177
  @measurement = Barometer::Measurement.new
188
178
  end
189
-
179
+
190
180
  it "changes state to successful (if successful)" do
191
181
  @measurement.success.should be_false
192
182
  @measurement.success!
193
183
  @measurement.utc_time_stamp.should be_nil
194
184
  @measurement.current.should be_nil
195
185
  @measurement.success.should be_false
196
-
186
+
197
187
  @measurement.current = Barometer::Measurement::Result.new
198
188
  @measurement.current.temperature = Data::Temperature.new
199
189
  @measurement.current.temperature.c = 10
@@ -201,7 +191,7 @@ describe "Measurement" do
201
191
  @measurement.success!
202
192
  @measurement.success.should be_true
203
193
  end
204
-
194
+
205
195
  it "returns successful state" do
206
196
  @measurement.current = Barometer::Measurement::Result.new
207
197
  @measurement.current.temperature = Data::Temperature.new
@@ -210,50 +200,32 @@ describe "Measurement" do
210
200
  @measurement.success.should be_true
211
201
  @measurement.success?.should be_true
212
202
  end
213
-
203
+
214
204
  it "returns non-successful state" do
215
205
  @measurement.success.should be_false
216
206
  @measurement.success?.should be_false
217
207
  end
218
-
208
+
219
209
  it "stamps the utc_time_stamp" do
220
210
  @measurement.utc_time_stamp.should be_nil
221
211
  @measurement.stamp!
222
212
  @measurement.utc_time_stamp.should_not be_nil
223
213
  end
224
-
214
+
225
215
  it "indicates if current" do
226
216
  @measurement.current.should be_nil
227
217
  @measurement.current?.should be_true
228
-
218
+
229
219
  @measurement.current = Barometer::Measurement::Result.new
230
220
  @measurement.current.current_at.should be_nil
231
221
  @measurement.current?.should be_true
232
-
222
+
233
223
  @measurement.current.current_at = Data::LocalTime.new(9,0,0)
234
224
  @measurement.current?.should be_true
235
225
  @measurement.current?("9:00 am").should be_true
236
-
237
-
238
- end
239
-
240
-
241
- # it "indicates if current" do
242
- # #@measurement.time.should be_nil
243
- # @measurement.current?.should be_false
244
- # @measurement.stamp!
245
- # @measurement.time.should_not be_nil
246
- # @measurement.current?.should be_true
247
- #
248
- # @measurement.time -= (60*60*3)
249
- # @measurement.current?.should be_true
250
- #
251
- # @measurement.time -= (60*60*5)
252
- # @measurement.current?.should be_false
253
- # end
254
-
255
- describe "changing units" do
226
+ end
256
227
 
228
+ describe "changing units" do
257
229
  before(:each) do
258
230
  @measurement = Barometer::Measurement.new
259
231
  end
@@ -278,16 +250,13 @@ describe "Measurement" do
278
250
  @measurement.metric!
279
251
  @measurement.metric?.should be_true
280
252
  end
281
-
282
253
  end
283
-
284
254
  end
285
-
255
+
286
256
  describe "when searching forecasts using 'for'" do
287
-
288
257
  before(:each) do
289
258
  @measurement = Barometer::Measurement.new
290
-
259
+
291
260
  # create a measurement object with a result array that includes
292
261
  # dates for 4 consecutive days starting with tommorrow
293
262
  @measurement.forecast = Barometer::Measurement::ResultArray.new
@@ -297,139 +266,116 @@ describe "Measurement" do
297
266
  @measurement.forecast << forecast_measurement
298
267
  end
299
268
  @measurement.forecast.size.should == 4
300
-
269
+
301
270
  @tommorrow = (Time.now + (60 * 60 * 24))
302
271
  end
303
-
272
+
304
273
  it "returns nil when there are no forecasts" do
305
274
  @measurement.forecast = Barometer::Measurement::ResultArray.new
306
275
  @measurement.forecast.size.should == 0
307
276
  @measurement.for.should be_nil
308
277
  end
309
-
278
+
310
279
  it "finds the date using a String" do
311
280
  tommorrow = @tommorrow.to_s
312
281
  tommorrow.class.should == String
313
282
  @measurement.for(tommorrow).should == @measurement.forecast.first
314
283
  end
315
-
284
+
316
285
  it "finds the date using a Date" do
317
286
  tommorrow = Date.parse(@tommorrow.to_s)
318
287
  tommorrow.class.should == Date
319
288
  @measurement.for(tommorrow).should == @measurement.forecast.first
320
289
  end
321
-
290
+
322
291
  it "finds the date using a DateTime" do
323
292
  tommorrow = DateTime.parse(@tommorrow.to_s)
324
293
  tommorrow.class.should == DateTime
325
294
  @measurement.for(tommorrow).should == @measurement.forecast.first
326
295
  end
327
-
296
+
328
297
  it "finds the date using a Time" do
329
298
  @tommorrow.class.should == Time
330
299
  @measurement.for(@tommorrow).should == @measurement.forecast.first
331
300
  end
332
-
301
+
333
302
  it "fidns the date using Data::LocalDateTime" do
334
303
  tommorrow = Data::LocalDateTime.parse(@tommorrow.to_s)
335
304
  tommorrow.class.should == Data::LocalDateTime
336
305
  @measurement.for(tommorrow).should == @measurement.forecast.first
337
306
  end
338
-
307
+
339
308
  it "finds nothing when there is not a match" do
340
309
  yesterday = (Time.now - (60 * 60 * 24))
341
310
  yesterday.class.should == Time
342
311
  @measurement.for(yesterday).should be_nil
343
312
  end
344
-
345
313
  end
346
-
314
+
347
315
  describe "when answering the simple questions," do
348
-
349
316
  before(:each) do
350
317
  @measurement = Barometer::Measurement.new(:wunderground)
351
318
  @measurement.current = Barometer::Measurement::Result.new
352
319
  @now = Data::LocalDateTime.parse("2009-05-01 2:05 pm")
353
320
  end
354
-
355
- # def windy?(time_string=nil, threshold=10)
356
- # local_time = Data::LocalTime.parse(time_string)
357
- # if current?(local_time)
358
- # return nil unless current
359
- # current.windy?(threshold)
360
- # else
361
- # return nil unless forecast && (future = forecast[local_time])
362
- # future.windy?(threshold)
363
- # end
364
- # end
365
-
321
+
366
322
  describe "windy?" do
367
-
368
323
  it "returns true if a current_measurement returns true" do
369
- @measurement.current.stubs(:windy?).returns(true)
324
+ @measurement.current.stub(:windy? => true)
370
325
  @measurement.windy?.should be_true
371
326
  end
372
-
327
+
373
328
  it "returns false if a current_measurement returns false" do
374
- @measurement.current.stubs(:windy?).returns(false)
329
+ @measurement.current.stub(:windy? => false)
375
330
  @measurement.windy?.should be_false
376
331
  end
377
-
378
332
  end
379
-
333
+
380
334
  describe "wet?" do
381
-
382
335
  it "returns true if the current_measurement returns true" do
383
- @measurement.current.stubs(:wet?).returns(true)
336
+ @measurement.current.stub(:wet? => true)
384
337
  @measurement.wet?.should be_true
385
338
  end
386
-
339
+
387
340
  it "returns false if the current_measurement returns false" do
388
- @measurement.current.stubs(:wet?).returns(false)
341
+ @measurement.current.stub(:wet? => false)
389
342
  @measurement.wet?.should be_false
390
343
  end
391
-
392
344
  end
393
-
345
+
394
346
  describe "day?" do
395
-
396
347
  it "returns true if the current_measurement returns true" do
397
- @measurement.current.stubs(:day?).returns(true)
348
+ @measurement.current.stub(:day? => true)
398
349
  @measurement.day?.should be_true
399
350
  end
400
-
351
+
401
352
  it "returns false if the current_measurement returns false" do
402
- @measurement.current.stubs(:day?).returns(false)
353
+ @measurement.current.stub(:day? => false)
403
354
  @measurement.day?.should be_false
404
355
  end
405
-
406
356
  end
407
-
357
+
408
358
  describe "sunny?" do
409
-
410
359
  it "returns true if the current_measurement returns true and day" do
411
- @measurement.current.stubs(:day?).returns(true)
412
- @measurement.current.stubs(:sunny?).returns(true)
360
+ @measurement.current.stub(:day? => true)
361
+ @measurement.current.stub(:sunny? => true)
413
362
  @measurement.day?.should be_true
414
363
  @measurement.sunny?.should be_true
415
364
  end
416
-
365
+
417
366
  it "returns false if the current_measurement returns false and day" do
418
- @measurement.current.stubs(:day?).returns(true)
419
- @measurement.current.stubs(:sunny?).returns(false)
367
+ @measurement.current.stub(:day? => true)
368
+ @measurement.current.stub(:sunny? => false)
420
369
  @measurement.day?.should be_true
421
370
  @measurement.sunny?.should be_false
422
371
  end
423
-
372
+
424
373
  it "returns false if night time" do
425
- @measurement.current.stubs(:day?).returns(false)
426
- @measurement.current.stubs(:sunny?).returns(true)
374
+ @measurement.current.stub(:day? => false)
375
+ @measurement.current.stub(:sunny? => true)
427
376
  @measurement.day?.should be_false
428
377
  @measurement.sunny?.should be_false
429
378
  end
430
-
431
379
  end
432
-
433
380
  end
434
-
435
381
  end