attack-barometer 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.rdoc +51 -9
  2. data/VERSION.yml +1 -1
  3. data/bin/barometer +57 -7
  4. data/lib/barometer/base.rb +3 -0
  5. data/lib/barometer/data/sun.rb +10 -0
  6. data/lib/barometer/data/zone.rb +79 -188
  7. data/lib/barometer/data.rb +11 -6
  8. data/lib/barometer/formats/coordinates.rb +4 -1
  9. data/lib/barometer/formats/geocode.rb +9 -7
  10. data/lib/barometer/formats/icao.rb +2 -2
  11. data/lib/barometer/formats/weather_id.rb +2 -2
  12. data/lib/barometer/measurements/common.rb +113 -0
  13. data/lib/barometer/{data → measurements}/current.rb +17 -42
  14. data/lib/barometer/measurements/forecast.rb +62 -0
  15. data/lib/barometer/measurements/forecast_array.rb +72 -0
  16. data/lib/barometer/{data → measurements}/measurement.rb +57 -45
  17. data/lib/barometer/measurements/night.rb +27 -0
  18. data/lib/barometer/query.rb +55 -5
  19. data/lib/barometer/services.rb +3 -1
  20. data/lib/barometer/translations/zone_codes.yml +360 -0
  21. data/lib/barometer/weather.rb +5 -4
  22. data/lib/barometer/weather_services/google.rb +19 -35
  23. data/lib/barometer/weather_services/service.rb +113 -255
  24. data/lib/barometer/weather_services/weather_bug.rb +291 -2
  25. data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
  26. data/lib/barometer/weather_services/wunderground.rb +83 -89
  27. data/lib/barometer/weather_services/yahoo.rb +44 -91
  28. data/lib/barometer/web_services/geocode.rb +1 -0
  29. data/lib/barometer/web_services/timezone.rb +40 -0
  30. data/lib/barometer/web_services/weather_id.rb +17 -2
  31. data/lib/barometer.rb +11 -0
  32. data/lib/demometer/demometer.rb +28 -0
  33. data/lib/demometer/public/css/master.css +259 -1
  34. data/lib/demometer/views/index.erb +2 -0
  35. data/lib/demometer/views/layout.erb +3 -2
  36. data/lib/demometer/views/measurement.erb +4 -1
  37. data/lib/demometer/views/readme.erb +116 -88
  38. data/spec/data/sun_spec.rb +53 -0
  39. data/spec/data/zone_spec.rb +330 -100
  40. data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
  41. data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
  42. data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
  43. data/spec/formats/weather_id_spec.rb +10 -5
  44. data/spec/measurements/common_spec.rb +352 -0
  45. data/spec/{data → measurements}/current_spec.rb +40 -103
  46. data/spec/measurements/forecast_array_spec.rb +165 -0
  47. data/spec/measurements/forecast_spec.rb +135 -0
  48. data/spec/{data → measurements}/measurement_spec.rb +86 -107
  49. data/spec/measurements/night_measurement_spec.rb +49 -0
  50. data/spec/query_spec.rb +12 -2
  51. data/spec/spec_helper.rb +28 -1
  52. data/spec/weather_services/google_spec.rb +27 -117
  53. data/spec/weather_services/services_spec.rb +49 -1024
  54. data/spec/weather_services/weather_bug_spec.rb +274 -0
  55. data/spec/weather_services/weather_dot_com_spec.rb +45 -125
  56. data/spec/weather_services/wunderground_spec.rb +42 -136
  57. data/spec/weather_services/yahoo_spec.rb +26 -116
  58. data/spec/weather_spec.rb +45 -45
  59. metadata +23 -11
  60. data/lib/barometer/data/forecast.rb +0 -84
  61. data/lib/barometer/data/night.rb +0 -69
  62. data/lib/barometer/extensions/graticule.rb +0 -51
  63. data/spec/data/forecast_spec.rb +0 -192
  64. data/spec/data/night_measurement_spec.rb +0 -136
@@ -11,7 +11,11 @@ describe "Google" do
11
11
  describe "the class methods" do
12
12
 
13
13
  it "defines accepted_formats" do
14
- WeatherService::Google.accepted_formats.should == @accepted_formats
14
+ WeatherService::Google._accepted_formats.should == @accepted_formats
15
+ end
16
+
17
+ it "defines source_name" do
18
+ WeatherService::Google._source_name.should == :google
15
19
  end
16
20
 
17
21
  # it "defines base_uri" do
@@ -19,7 +23,7 @@ describe "Google" do
19
23
  # end
20
24
 
21
25
  it "defines get_all" do
22
- WeatherService::Google.respond_to?("get_all").should be_true
26
+ WeatherService::Google.respond_to?("_fetch").should be_true
23
27
  end
24
28
 
25
29
  end
@@ -27,17 +31,17 @@ describe "Google" do
27
31
  describe "building the current data" do
28
32
 
29
33
  it "defines the build method" do
30
- WeatherService::Google.respond_to?("build_current").should be_true
34
+ WeatherService::Google.respond_to?("_build_current").should be_true
31
35
  end
32
36
 
33
37
  it "requires Hash input" do
34
- lambda { WeatherService::Google.build_current }.should raise_error(ArgumentError)
35
- lambda { WeatherService::Google.build_current({}) }.should_not raise_error(ArgumentError)
38
+ lambda { WeatherService::Google._build_current }.should raise_error(ArgumentError)
39
+ lambda { WeatherService::Google._build_current({}) }.should_not raise_error(ArgumentError)
36
40
  end
37
41
 
38
- it "returns Barometer::CurrentMeasurement object" do
39
- current = WeatherService::Google.build_current({})
40
- current.is_a?(Data::CurrentMeasurement).should be_true
42
+ it "returns Measurement::Current object" do
43
+ current = WeatherService::Google._build_current({})
44
+ current.is_a?(Measurement::Current).should be_true
41
45
  end
42
46
 
43
47
  end
@@ -45,17 +49,17 @@ describe "Google" do
45
49
  describe "building the forecast data" do
46
50
 
47
51
  it "defines the build method" do
48
- WeatherService::Google.respond_to?("build_forecast").should be_true
52
+ WeatherService::Google.respond_to?("_build_forecast").should be_true
49
53
  end
50
54
 
51
55
  it "requires Hash input" do
52
- lambda { WeatherService::Google.build_forecast }.should raise_error(ArgumentError)
53
- lambda { WeatherService::Google.build_forecast({}) }.should_not raise_error(ArgumentError)
56
+ lambda { WeatherService::Google._build_forecast }.should raise_error(ArgumentError)
57
+ lambda { WeatherService::Google._build_forecast({}) }.should_not raise_error(ArgumentError)
54
58
  end
55
59
 
56
60
  it "returns Array object" do
57
- current = WeatherService::Google.build_forecast({})
58
- current.is_a?(Array).should be_true
61
+ current = WeatherService::Google._build_forecast({})
62
+ current.is_a?(Measurement::ForecastArray).should be_true
59
63
  end
60
64
 
61
65
  end
@@ -63,18 +67,18 @@ describe "Google" do
63
67
  describe "building the location data" do
64
68
 
65
69
  it "defines the build method" do
66
- WeatherService::Google.respond_to?("build_location").should be_true
70
+ WeatherService::Google.respond_to?("_build_location").should be_true
67
71
  end
68
72
 
69
73
  it "requires Barometer::Geo input" do
70
74
  geo = Data::Geo.new({})
71
- lambda { WeatherService::Google.build_location({}) }.should raise_error(ArgumentError)
72
- lambda { WeatherService::Google.build_location(geo) }.should_not raise_error(ArgumentError)
75
+ lambda { WeatherService::Google._build_location(nil,{}) }.should raise_error(ArgumentError)
76
+ lambda { WeatherService::Google._build_location(nil,geo) }.should_not raise_error(ArgumentError)
73
77
  end
74
78
 
75
79
  it "returns Barometer::Location object" do
76
80
  geo = Data::Geo.new({})
77
- location = WeatherService::Google.build_location(geo)
81
+ location = WeatherService::Google._build_location(nil,geo)
78
82
  location.is_a?(Data::Location).should be_true
79
83
  end
80
84
 
@@ -97,7 +101,7 @@ describe "Google" do
97
101
 
98
102
  before(:each) do
99
103
  @query = Barometer::Query.new("Calgary,AB")
100
- @measurement = Data::Measurement.new
104
+ @measurement = Barometer::Measurement.new
101
105
 
102
106
  FakeWeb.register_uri(:get,
103
107
  "http://google.com/ig/api?weather=#{CGI.escape(@query.q)}&hl=en-GB",
@@ -116,8 +120,8 @@ describe "Google" do
116
120
 
117
121
  it "requires a Barometer::Measurement object" do
118
122
  lambda { Barometer::WeatherService::Google._measure(nil, @query) }.should raise_error(ArgumentError)
119
- lambda { Barometer::WeatherService::Google._measure("invlaid", @query) }.should raise_error(ArgumentError)
120
-
123
+ lambda { Barometer::WeatherService::Google._measure("invalid", @query) }.should raise_error(ArgumentError)
124
+
121
125
  lambda { Barometer::WeatherService::Google._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
122
126
  end
123
127
 
@@ -130,109 +134,15 @@ describe "Google" do
130
134
 
131
135
  it "returns a Barometer::Measurement object" do
132
136
  result = Barometer::WeatherService::Google._measure(@measurement, @query)
133
- result.is_a?(Data::Measurement).should be_true
134
- result.current.is_a?(Data::CurrentMeasurement).should be_true
135
- result.forecast.is_a?(Array).should be_true
136
-
137
- result.source.should == :google
137
+ result.is_a?(Barometer::Measurement).should be_true
138
+ result.current.is_a?(Measurement::Current).should be_true
139
+ result.forecast.is_a?(Measurement::ForecastArray).should be_true
138
140
  end
139
141
 
140
142
  end
141
143
 
142
144
  end
143
145
 
144
- describe "when answering the simple questions," do
145
-
146
- before(:each) do
147
- @measurement = Data::Measurement.new
148
- end
149
-
150
- describe "currently_wet_by_icon?" do
151
-
152
- before(:each) do
153
- @measurement.current = Data::CurrentMeasurement.new
154
- end
155
-
156
- it "returns true if matching icon code" do
157
- @measurement.current.icon = "rain"
158
- @measurement.current.icon?.should be_true
159
- WeatherService::Google.currently_wet_by_icon?(@measurement.current).should be_true
160
- end
161
-
162
- it "returns false if NO matching icon code" do
163
- @measurement.current.icon = "sunny"
164
- @measurement.current.icon?.should be_true
165
- WeatherService::Google.currently_wet_by_icon?(@measurement.current).should be_false
166
- end
167
-
168
- end
169
-
170
- describe "forecasted_wet_by_icon?" do
171
-
172
- before(:each) do
173
- @measurement.forecast = [Data::ForecastMeasurement.new]
174
- @measurement.forecast.first.date = Date.today
175
- @measurement.forecast.size.should == 1
176
- end
177
-
178
- it "returns true if matching icon code" do
179
- @measurement.forecast.first.icon = "rain"
180
- @measurement.forecast.first.icon?.should be_true
181
- WeatherService::Google.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
182
- end
183
-
184
- it "returns false if NO matching icon code" do
185
- @measurement.forecast.first.icon = "sunny"
186
- @measurement.forecast.first.icon?.should be_true
187
- WeatherService::Google.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
188
- end
189
-
190
- end
191
-
192
- describe "currently_sunny_by_icon?" do
193
-
194
- before(:each) do
195
- @measurement.current = Data::CurrentMeasurement.new
196
- end
197
-
198
- it "returns true if matching icon code" do
199
- @measurement.current.icon = "sunny"
200
- @measurement.current.icon?.should be_true
201
- WeatherService::Google.currently_sunny_by_icon?(@measurement.current).should be_true
202
- end
203
-
204
- it "returns false if NO matching icon code" do
205
- @measurement.current.icon = "rain"
206
- @measurement.current.icon?.should be_true
207
- WeatherService::Google.currently_sunny_by_icon?(@measurement.current).should be_false
208
- end
209
-
210
- end
211
-
212
- describe "forecasted_sunny_by_icon?" do
213
-
214
- before(:each) do
215
- @measurement.forecast = [Data::ForecastMeasurement.new]
216
- @measurement.forecast.first.date = Date.today
217
- @measurement.forecast.size.should == 1
218
- end
219
-
220
- it "returns true if matching icon code" do
221
- @measurement.forecast.first.icon = "sunny"
222
- @measurement.forecast.first.icon?.should be_true
223
- WeatherService::Google.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
224
- end
225
-
226
- it "returns false if NO matching icon code" do
227
- @measurement.forecast.first.icon = "rain"
228
- @measurement.forecast.first.icon?.should be_true
229
- WeatherService::Google.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
230
- end
231
-
232
- end
233
-
234
- end
235
-
236
146
  # describe "overall data correctness" do
237
147
  #
238
148
  # before(:each) do