barometer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +266 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/barometer +63 -0
  5. data/lib/barometer.rb +52 -0
  6. data/lib/barometer/base.rb +52 -0
  7. data/lib/barometer/data.rb +15 -0
  8. data/lib/barometer/data/current.rb +93 -0
  9. data/lib/barometer/data/distance.rb +131 -0
  10. data/lib/barometer/data/forecast.rb +66 -0
  11. data/lib/barometer/data/geo.rb +98 -0
  12. data/lib/barometer/data/location.rb +20 -0
  13. data/lib/barometer/data/measurement.rb +161 -0
  14. data/lib/barometer/data/pressure.rb +133 -0
  15. data/lib/barometer/data/speed.rb +147 -0
  16. data/lib/barometer/data/sun.rb +35 -0
  17. data/lib/barometer/data/temperature.rb +164 -0
  18. data/lib/barometer/data/units.rb +55 -0
  19. data/lib/barometer/data/zone.rb +124 -0
  20. data/lib/barometer/extensions/graticule.rb +50 -0
  21. data/lib/barometer/extensions/httparty.rb +21 -0
  22. data/lib/barometer/query.rb +228 -0
  23. data/lib/barometer/services.rb +6 -0
  24. data/lib/barometer/services/google.rb +146 -0
  25. data/lib/barometer/services/noaa.rb +6 -0
  26. data/lib/barometer/services/service.rb +324 -0
  27. data/lib/barometer/services/weather_bug.rb +6 -0
  28. data/lib/barometer/services/weather_dot_com.rb +6 -0
  29. data/lib/barometer/services/wunderground.rb +285 -0
  30. data/lib/barometer/services/yahoo.rb +274 -0
  31. data/lib/barometer/weather.rb +187 -0
  32. data/spec/barometer_spec.rb +162 -0
  33. data/spec/data_current_spec.rb +225 -0
  34. data/spec/data_distance_spec.rb +336 -0
  35. data/spec/data_forecast_spec.rb +150 -0
  36. data/spec/data_geo_spec.rb +90 -0
  37. data/spec/data_location_spec.rb +59 -0
  38. data/spec/data_measurement_spec.rb +411 -0
  39. data/spec/data_pressure_spec.rb +336 -0
  40. data/spec/data_speed_spec.rb +374 -0
  41. data/spec/data_sun_spec.rb +76 -0
  42. data/spec/data_temperature_spec.rb +396 -0
  43. data/spec/data_zone_spec.rb +133 -0
  44. data/spec/fixtures/current_calgary_ab.xml +1 -0
  45. data/spec/fixtures/forecast_calgary_ab.xml +1 -0
  46. data/spec/fixtures/geocode_40_73.xml +1 -0
  47. data/spec/fixtures/geocode_90210.xml +1 -0
  48. data/spec/fixtures/geocode_T5B4M9.xml +1 -0
  49. data/spec/fixtures/geocode_calgary_ab.xml +1 -0
  50. data/spec/fixtures/geocode_newyork_ny.xml +1 -0
  51. data/spec/fixtures/google_calgary_ab.xml +1 -0
  52. data/spec/fixtures/yahoo_90210.xml +1 -0
  53. data/spec/query_spec.rb +469 -0
  54. data/spec/service_google_spec.rb +144 -0
  55. data/spec/service_wunderground_spec.rb +330 -0
  56. data/spec/service_yahoo_spec.rb +299 -0
  57. data/spec/services_spec.rb +1106 -0
  58. data/spec/spec_helper.rb +14 -0
  59. data/spec/units_spec.rb +101 -0
  60. data/spec/weather_spec.rb +265 -0
  61. metadata +119 -0
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'fakeweb'
4
+ require 'cgi'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'barometer'
9
+
10
+ FakeWeb.allow_net_connect = false
11
+
12
+ Spec::Runner.configure do |config|
13
+
14
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Units" do
4
+
5
+ describe "when initialized" do
6
+
7
+ before(:each) do
8
+ @units = Barometer::Units.new
9
+ end
10
+
11
+ it "responds to metric, defaults to true" do
12
+ @units.metric.should be_true
13
+ end
14
+
15
+ it "allows metric to be set" do
16
+ @units.metric.should be_true
17
+
18
+ @units2 = Barometer::Units.new(false)
19
+ @units2.metric.should be_false
20
+ end
21
+
22
+ it "stubs metric_default" do
23
+ lambda { @units.metric_default = 5 }.should raise_error(NotImplementedError)
24
+ end
25
+
26
+ it "stubs imperial_default" do
27
+ lambda { @units.imperial_default = 5 }.should raise_error(NotImplementedError)
28
+ end
29
+
30
+ end
31
+
32
+ describe "changing units" do
33
+
34
+ before(:each) do
35
+ @units = Barometer::Units.new
36
+ end
37
+
38
+ it "indicates if metric?" do
39
+ @units.metric.should be_true
40
+ @units.metric?.should be_true
41
+ @units.metric = false
42
+ @units.metric.should be_false
43
+ @units.metric?.should be_false
44
+ end
45
+
46
+ it "changes to imperial" do
47
+ @units.metric?.should be_true
48
+ @units.imperial!
49
+ @units.metric?.should be_false
50
+ end
51
+
52
+ it "changes to metric" do
53
+ @units.metric = false
54
+ @units.metric?.should be_false
55
+ @units.metric!
56
+ @units.metric?.should be_true
57
+ end
58
+
59
+ end
60
+
61
+ describe "when assigning values" do
62
+
63
+ before(:each) do
64
+ module Barometer
65
+ class Units
66
+ attr_accessor :a, :b
67
+ def metric_default=(value)
68
+ self.a = value
69
+ end
70
+ def imperial_default=(value)
71
+ self.b = value
72
+ end
73
+ end
74
+ end
75
+ @units_metric = Barometer::Units.new(true)
76
+ @units_imperial = Barometer::Units.new(false)
77
+ @test_value_a = 5.5
78
+ @test_value_b = 9.9
79
+ end
80
+
81
+ it "assigns metric_default" do
82
+ @units_metric.metric?.should be_true
83
+ @units_metric << @test_value_a
84
+ @units_metric.a.should == @test_value_a
85
+
86
+ @units_metric << [@test_value_b, @test_value_a]
87
+ @units_metric.a.should == @test_value_b
88
+ end
89
+
90
+ it "assigns imperial_default" do
91
+ @units_imperial.metric?.should be_false
92
+ @units_imperial << @test_value_a
93
+ @units_imperial.b.should == @test_value_a
94
+
95
+ @units_imperial << [@test_value_a, @test_value_b]
96
+ @units_imperial.b.should == @test_value_b
97
+ end
98
+
99
+ end
100
+
101
+ end
@@ -0,0 +1,265 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Weather" do
4
+
5
+ describe "when initialized" do
6
+
7
+ before(:each) do
8
+ @weather = Barometer::Weather.new
9
+ end
10
+
11
+ it "responds to measurements (and sets default value)" do
12
+ @weather.measurements.should == []
13
+ end
14
+
15
+ it "responds to current" do
16
+ @weather.respond_to?("current").should be_true
17
+ end
18
+
19
+ it "responds to forecast" do
20
+ @weather.respond_to?("forecast").should be_true
21
+ end
22
+
23
+ it "responds to today" do
24
+ @weather.respond_to?("today").should be_true
25
+ end
26
+
27
+ it "responds to tommorrow" do
28
+ @weather.respond_to?("tomorrow").should be_true
29
+ end
30
+
31
+ it "responds to for" do
32
+ @weather.respond_to?("for").should be_true
33
+ end
34
+
35
+ end
36
+
37
+ describe "with measurements" do
38
+
39
+ before(:each) do
40
+ module Barometer
41
+ class Measurement
42
+ attr_accessor :success
43
+ end
44
+ end
45
+ @weather = Barometer::Weather.new
46
+ @wunderground = Barometer::Measurement.new(:wunderground)
47
+ @wunderground.success = true
48
+ @yahoo = Barometer::Measurement.new(:yahoo)
49
+ @yahoo.success = true
50
+ @google = Barometer::Measurement.new(:google)
51
+ @weather.measurements << @wunderground
52
+ @weather.measurements << @yahoo
53
+ @weather.measurements << @google
54
+ end
55
+
56
+ it "retrieves a source measurement" do
57
+ lambda { @weather.source(1) }.should raise_error(ArgumentError)
58
+ lambda { @weather.source("valid") }.should_not raise_error(ArgumentError)
59
+ lambda { @weather.source(:valid) }.should_not raise_error(ArgumentError)
60
+ @weather.source(:does_not_exist).should be_nil
61
+ @weather.source(:wunderground).should == @wunderground
62
+ end
63
+
64
+ it "lists the sources of measurements (that were successful)" do
65
+ sources = @weather.sources
66
+ sources.should_not be_nil
67
+ @wunderground.success?.should be_true
68
+ sources.include?(:wunderground).should be_true
69
+ @yahoo.success?.should be_true
70
+ sources.include?(:yahoo).should be_true
71
+ @google.success?.should be_false
72
+ sources.include?(:google).should be_false
73
+ end
74
+
75
+ it "returns the default source" do
76
+ @weather.default.should == @wunderground
77
+ end
78
+
79
+ end
80
+
81
+ describe "when answering the simple questions," do
82
+
83
+ before(:each) do
84
+ @weather = Barometer::Weather.new
85
+ end
86
+
87
+ describe "windy?" do
88
+
89
+ it "requires threshold as a number" do
90
+ lambda { @weather.windy?("a") }.should raise_error(ArgumentError)
91
+ lambda { @weather.windy?(1) }.should_not raise_error(ArgumentError)
92
+ lambda { @weather.windy?(1.1) }.should_not raise_error(ArgumentError)
93
+ end
94
+
95
+ it "requires time as a Time object" do
96
+ lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
97
+ lambda { @weather.windy?(1,Time.now.utc) }.should_not raise_error(ArgumentError)
98
+ end
99
+
100
+ it "returns nil when no measurements" do
101
+ @weather.measurements.should be_empty
102
+ @weather.windy?.should be_nil
103
+ end
104
+
105
+ it "returns true if a measurement returns true" do
106
+ wunderground = Barometer::Measurement.new(:wunderground)
107
+ wunderground.success = true
108
+ @weather.measurements << wunderground
109
+ module Barometer; class Measurement
110
+ def windy?(a=nil,b=nil); true; end
111
+ end; end
112
+ @weather.windy?.should be_true
113
+ end
114
+
115
+ it "returns false if a measurement returns false" do
116
+ wunderground = Barometer::Measurement.new(:wunderground)
117
+ wunderground.success = true
118
+ @weather.measurements << wunderground
119
+ module Barometer; class Measurement
120
+ def windy?(a=nil,b=nil); false; end
121
+ end; end
122
+ @weather.windy?.should be_false
123
+ end
124
+
125
+ end
126
+
127
+ describe "wet?" do
128
+
129
+ it "requires threshold as a number" do
130
+ lambda { @weather.wet?("a") }.should raise_error(ArgumentError)
131
+ lambda { @weather.wet?(1) }.should_not raise_error(ArgumentError)
132
+ lambda { @weather.wet?(1.1) }.should_not raise_error(ArgumentError)
133
+ end
134
+
135
+ it "requires time as a Time object" do
136
+ lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
137
+ lambda { @weather.wet?(1,Time.now.utc) }.should_not raise_error(ArgumentError)
138
+ end
139
+
140
+ it "returns nil when no measurements" do
141
+ @weather.measurements.should be_empty
142
+ @weather.wet?.should be_nil
143
+ end
144
+
145
+ it "returns true if a measurement returns true" do
146
+ wunderground = Barometer::Measurement.new(:wunderground)
147
+ wunderground.success = true
148
+ @weather.measurements << wunderground
149
+ module Barometer; class Measurement
150
+ def wet?(a=nil,b=nil); true; end
151
+ end; end
152
+ @weather.wet?.should be_true
153
+ end
154
+
155
+ it "returns false if a measurement returns false" do
156
+ wunderground = Barometer::Measurement.new(:wunderground)
157
+ wunderground.success = true
158
+ @weather.measurements << wunderground
159
+ module Barometer; class Measurement
160
+ def wet?(a=nil,b=nil); false; end
161
+ end; end
162
+ @weather.wet?.should be_false
163
+ end
164
+
165
+ end
166
+
167
+ describe "day? and night?" do
168
+
169
+ it "requires time as a Time object" do
170
+ lambda { @weather.day?("a") }.should raise_error(ArgumentError)
171
+ lambda { @weather.day?(Time.now.utc) }.should_not raise_error(ArgumentError)
172
+ end
173
+
174
+ it "requires time as a Time object" do
175
+ lambda { @weather.night?("a") }.should raise_error(ArgumentError)
176
+ lambda { @weather.night?(Time.now.utc) }.should_not raise_error(ArgumentError)
177
+ end
178
+
179
+ it "returns nil when no measurements" do
180
+ @weather.measurements.should be_empty
181
+ @weather.day?.should be_nil
182
+ @weather.night?.should be_nil
183
+ end
184
+
185
+ it "returns true if a measurement returns true (night is opposite)" do
186
+ wunderground = Barometer::Measurement.new(:wunderground)
187
+ wunderground.success = true
188
+ @weather.measurements << wunderground
189
+ module Barometer; class Measurement
190
+ def day?(a=nil); true; end
191
+ end; end
192
+ @weather.day?.should be_true
193
+ @weather.night?.should be_false
194
+ end
195
+
196
+ it "returns false if a measurement returns false (night is opposite)" do
197
+ wunderground = Barometer::Measurement.new(:wunderground)
198
+ wunderground.success = true
199
+ @weather.measurements << wunderground
200
+ module Barometer; class Measurement
201
+ def day?(a=nil); false; end
202
+ end; end
203
+ @weather.day?.should be_false
204
+ @weather.night?.should be_true
205
+ end
206
+
207
+ end
208
+
209
+ describe "sunny?" do
210
+
211
+ it "requires time as a Time object" do
212
+ lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
213
+ lambda { @weather.sunny?(Time.now.utc) }.should_not raise_error(ArgumentError)
214
+ end
215
+
216
+ it "returns nil when no measurements" do
217
+ @weather.measurements.should be_empty
218
+ @weather.sunny?.should be_nil
219
+ end
220
+
221
+ it "returns true if a measurement returns true" do
222
+ wunderground = Barometer::Measurement.new(:wunderground)
223
+ wunderground.success = true
224
+ @weather.measurements << wunderground
225
+ module Barometer; class Measurement
226
+ def day?(a=nil); true; end
227
+ end; end
228
+ module Barometer; class Measurement
229
+ def sunny?(a=nil,b=nil); true; end
230
+ end; end
231
+ @weather.sunny?.should be_true
232
+ end
233
+
234
+ it "returns false if a measurement returns false" do
235
+ wunderground = Barometer::Measurement.new(:wunderground)
236
+ wunderground.success = true
237
+ @weather.measurements << wunderground
238
+ module Barometer; class Measurement
239
+ def day?(a=nil); true; end
240
+ end; end
241
+ module Barometer; class Measurement
242
+ def sunny?(a=nil,b=nil); false; end
243
+ end; end
244
+ @weather.sunny?.should be_false
245
+ end
246
+
247
+ it "returns false if night time" do
248
+ wunderground = Barometer::Measurement.new(:wunderground)
249
+ wunderground.success = true
250
+ @weather.measurements << wunderground
251
+ module Barometer; class Measurement
252
+ def sunny?(a=nil,b=nil); true; end
253
+ end; end
254
+ @weather.sunny?.should be_true
255
+ module Barometer; class Measurement
256
+ def day?(a=nil); false; end
257
+ end; end
258
+ @weather.sunny?.should be_false
259
+ end
260
+
261
+ end
262
+
263
+ end
264
+
265
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barometer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark G
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-30 00:00:00 -06:00
13
+ default_executable: barometer
14
+ dependencies: []
15
+
16
+ description:
17
+ email: barometer@attackcorp.com
18
+ executables:
19
+ - barometer
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - bin/barometer
29
+ - lib/barometer
30
+ - lib/barometer/base.rb
31
+ - lib/barometer/data
32
+ - lib/barometer/data/current.rb
33
+ - lib/barometer/data/distance.rb
34
+ - lib/barometer/data/forecast.rb
35
+ - lib/barometer/data/geo.rb
36
+ - lib/barometer/data/location.rb
37
+ - lib/barometer/data/measurement.rb
38
+ - lib/barometer/data/pressure.rb
39
+ - lib/barometer/data/speed.rb
40
+ - lib/barometer/data/sun.rb
41
+ - lib/barometer/data/temperature.rb
42
+ - lib/barometer/data/units.rb
43
+ - lib/barometer/data/zone.rb
44
+ - lib/barometer/data.rb
45
+ - lib/barometer/extensions
46
+ - lib/barometer/extensions/graticule.rb
47
+ - lib/barometer/extensions/httparty.rb
48
+ - 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
+ - lib/barometer/services.rb
58
+ - lib/barometer/weather.rb
59
+ - lib/barometer.rb
60
+ - spec/barometer_spec.rb
61
+ - spec/data_current_spec.rb
62
+ - spec/data_distance_spec.rb
63
+ - spec/data_forecast_spec.rb
64
+ - spec/data_geo_spec.rb
65
+ - spec/data_location_spec.rb
66
+ - spec/data_measurement_spec.rb
67
+ - spec/data_pressure_spec.rb
68
+ - spec/data_speed_spec.rb
69
+ - spec/data_sun_spec.rb
70
+ - spec/data_temperature_spec.rb
71
+ - spec/data_zone_spec.rb
72
+ - spec/fixtures
73
+ - spec/fixtures/current_calgary_ab.xml
74
+ - spec/fixtures/forecast_calgary_ab.xml
75
+ - spec/fixtures/geocode_40_73.xml
76
+ - spec/fixtures/geocode_90210.xml
77
+ - spec/fixtures/geocode_calgary_ab.xml
78
+ - spec/fixtures/geocode_newyork_ny.xml
79
+ - spec/fixtures/geocode_T5B4M9.xml
80
+ - spec/fixtures/google_calgary_ab.xml
81
+ - spec/fixtures/yahoo_90210.xml
82
+ - spec/query_spec.rb
83
+ - spec/service_google_spec.rb
84
+ - spec/service_wunderground_spec.rb
85
+ - spec/service_yahoo_spec.rb
86
+ - spec/services_spec.rb
87
+ - spec/spec_helper.rb
88
+ - spec/units_spec.rb
89
+ - spec/weather_spec.rb
90
+ - LICENSE
91
+ has_rdoc: true
92
+ homepage: http://github.com/attack/barometer
93
+ post_install_message:
94
+ rdoc_options:
95
+ - --inline-source
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: "0"
110
+ version:
111
+ requirements: []
112
+
113
+ rubyforge_project: barometer
114
+ rubygems_version: 1.3.1
115
+ signing_key:
116
+ specification_version: 2
117
+ summary: TODO
118
+ test_files: []
119
+