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,33 +1,28 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Result Array" do
4
-
3
+ describe Barometer::Measurement::ResultArray do
5
4
  describe "instance methods" do
6
-
7
5
  before(:each) do
8
- @array = Measurement::ResultArray.new
6
+ @array = Barometer::Measurement::ResultArray.new
9
7
  end
10
-
8
+
11
9
  describe "'<<'" do
12
-
13
- it "requires Measurement::Result" do
10
+ it "requires Barometer::Measurement::Result" do
14
11
  lambda { @array << "invalid" }.should raise_error(ArgumentError)
15
12
  end
16
-
13
+
17
14
  it "adds ForecastMeasurement" do
18
15
  @array.size.should == 0
19
- forecast = Measurement::Result.new
16
+ forecast = Barometer::Measurement::Result.new
20
17
  @array << forecast
21
18
  @array.size.should == 1
22
19
  end
23
-
24
20
  end
25
-
26
- describe "when searching forecasts using 'for'" do
27
21
 
22
+ describe "when searching forecasts using 'for'" do
28
23
  before(:each) do
29
24
  1.upto(4) do |i|
30
- forecast_measurement = Measurement::Result.new
25
+ forecast_measurement = Barometer::Measurement::Result.new
31
26
  forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
32
27
  @array << forecast_measurement
33
28
  end
@@ -37,7 +32,7 @@ describe "Result Array" do
37
32
  end
38
33
 
39
34
  it "returns nil when there are no forecasts" do
40
- @array = Measurement::ResultArray.new
35
+ @array = Barometer::Measurement::ResultArray.new
41
36
  @array.size.should == 0
42
37
  @array.for(@tommorrow).should be_nil
43
38
  end
@@ -76,38 +71,32 @@ describe "Result Array" do
76
71
  yesterday.class.should == Time
77
72
  @array.for(yesterday).should be_nil
78
73
  end
79
-
74
+
80
75
  it "finds using '[]'" do
81
76
  tommorrow = @tommorrow.to_s
82
77
  tommorrow.class.should == String
83
78
  @array[tommorrow].should == @array.first
84
79
  end
85
-
86
80
  end
87
-
88
81
  end
89
-
82
+
90
83
  describe "simple questions" do
91
-
92
84
  before(:each) do
93
- @array = Measurement::ResultArray.new
94
- #@early = Data::LocalTime("6:00 am")
95
- #@noon = Data::LocalTime("12:00 pm")
96
- #@late = Data::LocalTime("8:00 pm")
85
+ @array = Barometer::Measurement::ResultArray.new
97
86
  @now = Time.utc(2009,5,5,10,30,25)
98
-
87
+
99
88
  @sun_icons = %w(sunny)
100
-
89
+
101
90
  0.upto(1) do |i|
102
- forecast_measurement = Measurement::Result.new
91
+ forecast_measurement = Barometer::Measurement::Result.new
103
92
  forecast_measurement.date = Date.parse((@now + (i * 60 * 60 * 24)).to_s)
104
93
  wind = Data::Speed.new
105
94
  wind << (i * 5)
106
95
  forecast_measurement.wind = wind
107
96
  forecast_measurement.sun = Data::Sun.new(
108
97
  Data::LocalTime.parse("9:00 am"), Data::LocalTime.parse("3:00 pm"))
109
- forecast_measurement.icon = "sunny"
110
- forecast_measurement.pop = 40
98
+ forecast_measurement.icon = "sunny"
99
+ forecast_measurement.pop = 40
111
100
  forecast_measurement.humidity = 95
112
101
  @array << forecast_measurement
113
102
  end
@@ -117,13 +106,13 @@ describe "Result Array" do
117
106
  @earlier = (@now - (60 * 60 * 3))
118
107
  @later = (@now + (60 * 60 * 6))
119
108
  end
120
-
109
+
121
110
  it "answers windy?" do
122
111
  @array.windy?(@tommorrow).should be_false
123
112
  @array.windy?(@tommorrow,1).should be_true
124
113
  @array.windy?(@yesterday).should be_nil
125
114
  end
126
-
115
+
127
116
  it "answers day?" do
128
117
  @array.day?(@yesterday).should be_nil
129
118
  @array.day?(@earlier).should be_false
@@ -131,35 +120,31 @@ describe "Result Array" do
131
120
  @array.day?(@tommorrow).should be_true
132
121
  @array.day?(@now).should be_true
133
122
  end
134
-
123
+
135
124
  it "answers sunny?" do
136
125
  @array.sunny?(@tommorrow,%w(rain)).should be_false
137
126
  @array.sunny?(@tommorrow,@sun_icons).should be_true
138
127
  @array.sunny?(@yesterday).should be_nil
139
128
  end
140
-
129
+
141
130
  describe "wet?" do
142
-
143
131
  it "answers via pop" do
144
132
  @array.wet?(@tommorrow).should be_false
145
133
  @array.wet?(@tommorrow,nil,50).should be_false
146
134
  @array.wet?(@tommorrow,nil,30).should be_true
147
135
  end
148
-
136
+
149
137
  it "answers via humidity" do
150
138
  @array.wet?(@tommorrow).should be_false
151
139
  @array.wet?(@tommorrow,nil,50,99).should be_false
152
140
  @array.wet?(@tommorrow,nil,50,90).should be_true
153
141
  end
154
-
142
+
155
143
  it "answers via icon" do
156
144
  @array.wet?(@tommorrow,%w(rain)).should be_false
157
145
  # pretend that "sun" means wet
158
146
  @array.wet?(@tommorrow,@sun_icons).should be_true
159
147
  end
160
-
161
148
  end
162
-
163
149
  end
164
-
165
150
  end
@@ -1,45 +1,43 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe "Result Measurement" do
4
-
3
+ describe Barometer::Measurement::Result do
5
4
  describe "when initialized" do
6
-
7
5
  before(:each) do
8
- @result = Measurement::Result.new
6
+ @result = Barometer::Measurement::Result.new
9
7
  end
10
-
8
+
11
9
  it "responds to temperature" do
12
10
  @result.temperature.should be_nil
13
11
  end
14
-
12
+
15
13
  it "responds to dew_point" do
16
14
  @result.dew_point.should be_nil
17
15
  end
18
-
16
+
19
17
  it "responds to heat_index" do
20
18
  @result.heat_index.should be_nil
21
19
  end
22
-
20
+
23
21
  it "responds to wind_chill" do
24
22
  @result.wind_chill.should be_nil
25
23
  end
26
-
24
+
27
25
  it "responds to pressure" do
28
26
  @result.pressure.should be_nil
29
27
  end
30
-
28
+
31
29
  it "responds to visibility" do
32
30
  @result.pressure.should be_nil
33
31
  end
34
-
32
+
35
33
  it "responds to current_at" do
36
34
  @result.current_at.should be_nil
37
35
  end
38
-
36
+
39
37
  it "responds to updated_at" do
40
38
  @result.updated_at.should be_nil
41
39
  end
42
-
40
+
43
41
  it "responds to date" do
44
42
  @result.date.should be_nil
45
43
  end
@@ -47,217 +45,215 @@ describe "Result Measurement" do
47
45
  it "responds to low" do
48
46
  @result.low.should be_nil
49
47
  end
50
-
48
+
51
49
  it "responds to high" do
52
50
  @result.high.should be_nil
53
51
  end
54
-
52
+
55
53
  it "responds to pop" do
56
54
  @result.pop.should be_nil
57
55
  end
58
-
56
+
59
57
  it "responds to valid_start_date" do
60
58
  @result.valid_start_date.should be_nil
61
59
  end
62
-
60
+
63
61
  it "responds to valid_end_date" do
64
62
  @result.valid_end_date.should be_nil
65
63
  end
66
-
64
+
67
65
  it "responds to description" do
68
66
  @result.description.should be_nil
69
67
  end
70
-
68
+
71
69
  it "responds to humidity" do
72
70
  @result.humidity.should be_nil
73
71
  end
74
-
72
+
75
73
  it "responds to icon" do
76
74
  @result.icon.should be_nil
77
75
  end
78
-
76
+
79
77
  it "responds to condition" do
80
78
  @result.condition.should be_nil
81
79
  end
82
-
80
+
83
81
  it "responds to wind" do
84
82
  @result.wind.should be_nil
85
83
  end
86
-
84
+
87
85
  it "responds to sun" do
88
86
  @result.sun.should be_nil
89
87
  end
90
-
88
+
91
89
  it "responds to metric" do
92
90
  @result.metric.should be_true
93
91
  end
94
-
92
+
95
93
  it "responds to metric?" do
96
94
  @result.metric?.should be_true
97
95
  @result.metric = false
98
96
  @result.metric?.should be_false
99
97
  end
100
-
101
98
  end
102
-
99
+
103
100
  describe "when writing data" do
104
-
105
101
  before(:each) do
106
- @result = Measurement::Result.new
102
+ @result = Barometer::Measurement::Result.new
107
103
  end
108
-
104
+
109
105
  it "only accepts Data::Temperature for temperature" do
110
106
  invalid_data = 1
111
107
  invalid_data.class.should_not == Data::Temperature
112
108
  lambda { @result.temperature = invalid_data }.should raise_error(ArgumentError)
113
-
109
+
114
110
  valid_data = Data::Temperature.new
115
111
  valid_data.class.should == Data::Temperature
116
112
  lambda { @result.temperature = valid_data }.should_not raise_error(ArgumentError)
117
113
  end
118
-
114
+
119
115
  it "only accepts Data::Temperature for dew_point" do
120
116
  invalid_data = 1
121
117
  invalid_data.class.should_not == Data::Temperature
122
118
  lambda { @result.dew_point = invalid_data }.should raise_error(ArgumentError)
123
-
119
+
124
120
  valid_data = Data::Temperature.new
125
121
  valid_data.class.should == Data::Temperature
126
122
  lambda { @result.dew_point = valid_data }.should_not raise_error(ArgumentError)
127
123
  end
128
-
124
+
129
125
  it "only accepts Data::Temperature for heat_index" do
130
126
  invalid_data = 1
131
127
  invalid_data.class.should_not == Data::Temperature
132
128
  lambda { @result.heat_index = invalid_data }.should raise_error(ArgumentError)
133
-
129
+
134
130
  valid_data = Data::Temperature.new
135
131
  valid_data.class.should == Data::Temperature
136
132
  lambda { @result.heat_index = valid_data }.should_not raise_error(ArgumentError)
137
133
  end
138
-
134
+
139
135
  it "only accepts Data::Temperature for wind_chill" do
140
136
  invalid_data = 1
141
137
  invalid_data.class.should_not == Data::Temperature
142
138
  lambda { @result.wind_chill = invalid_data }.should raise_error(ArgumentError)
143
-
139
+
144
140
  valid_data = Data::Temperature.new
145
141
  valid_data.class.should == Data::Temperature
146
142
  lambda { @result.wind_chill = valid_data }.should_not raise_error(ArgumentError)
147
143
  end
148
-
144
+
149
145
  it "only accepts Data::Pressure for pressure" do
150
146
  invalid_data = 1
151
147
  invalid_data.class.should_not == Data::Pressure
152
148
  lambda { @result.pressure = invalid_data }.should raise_error(ArgumentError)
153
-
149
+
154
150
  valid_data = Data::Pressure.new
155
151
  valid_data.class.should == Data::Pressure
156
152
  lambda { @result.pressure = valid_data }.should_not raise_error(ArgumentError)
157
153
  end
158
-
154
+
159
155
  it "only accepts Data::Distance for visibility" do
160
156
  invalid_data = 1
161
157
  invalid_data.class.should_not == Data::Distance
162
158
  lambda { @result.visibility = invalid_data }.should raise_error(ArgumentError)
163
-
159
+
164
160
  valid_data = Data::Distance.new
165
161
  valid_data.class.should == Data::Distance
166
162
  lambda { @result.visibility = valid_data }.should_not raise_error(ArgumentError)
167
163
  end
168
-
164
+
169
165
  it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
170
166
  invalid_data = 1
171
167
  invalid_data.class.should_not == Data::LocalTime
172
168
  invalid_data.class.should_not == Data::LocalDateTime
173
169
  lambda { @result.current_at = invalid_data }.should raise_error(ArgumentError)
174
-
170
+
175
171
  valid_data = Data::LocalTime.new
176
172
  valid_data.class.should == Data::LocalTime
177
173
  lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
178
-
174
+
179
175
  valid_data = Data::LocalDateTime.new(2009,1,1)
180
176
  valid_data.class.should == Data::LocalDateTime
181
177
  lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
182
178
  end
183
-
179
+
184
180
  it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
185
181
  invalid_data = 1
186
182
  invalid_data.class.should_not == Data::LocalTime
187
183
  invalid_data.class.should_not == Data::LocalDateTime
188
184
  lambda { @result.updated_at = invalid_data }.should raise_error(ArgumentError)
189
-
185
+
190
186
  valid_data = Data::LocalTime.new
191
187
  valid_data.class.should == Data::LocalTime
192
188
  lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
193
-
189
+
194
190
  valid_data = Data::LocalDateTime.new(2009,1,1)
195
191
  valid_data.class.should == Data::LocalDateTime
196
192
  lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
197
193
  end
198
-
194
+
199
195
  it "only accepts Date for date" do
200
196
  invalid_data = 1
201
197
  invalid_data.class.should_not == Date
202
198
  lambda { @result.date = invalid_data }.should raise_error(ArgumentError)
203
-
199
+
204
200
  valid_data = Date.new
205
201
  valid_data.class.should == Date
206
202
  lambda { @result.date = valid_data }.should_not raise_error(ArgumentError)
207
203
  end
208
-
204
+
209
205
  it "only accepts Data::Temperature for high" do
210
206
  invalid_data = 1
211
207
  invalid_data.class.should_not == Data::Temperature
212
208
  lambda { @result.high = invalid_data }.should raise_error(ArgumentError)
213
-
209
+
214
210
  valid_data = Data::Temperature.new
215
211
  valid_data.class.should == Data::Temperature
216
212
  lambda { @result.high = valid_data }.should_not raise_error(ArgumentError)
217
213
  end
218
-
214
+
219
215
  it "only accepts Data::Temperature for low" do
220
216
  invalid_data = 1
221
217
  invalid_data.class.should_not == Data::Temperature
222
218
  lambda { @result.low = invalid_data }.should raise_error(ArgumentError)
223
-
219
+
224
220
  valid_data = Data::Temperature.new
225
221
  valid_data.class.should == Data::Temperature
226
222
  lambda { @result.low = valid_data }.should_not raise_error(ArgumentError)
227
223
  end
228
-
224
+
229
225
  it "only accepts Fixnum for pop" do
230
226
  invalid_data = "test"
231
227
  invalid_data.class.should_not == Fixnum
232
228
  lambda { @result.pop = invalid_data }.should raise_error(ArgumentError)
233
-
229
+
234
230
  valid_data = 50
235
231
  valid_data.class.should == Fixnum
236
232
  lambda { @result.pop = valid_data }.should_not raise_error(ArgumentError)
237
233
  end
238
-
234
+
239
235
  it "only accepts Data::LocalDateTime for valid_start_date" do
240
236
  invalid_data = 1
241
237
  invalid_data.class.should_not == Data::LocalDateTime
242
238
  lambda { @result.valid_start_date = invalid_data }.should raise_error(ArgumentError)
243
-
239
+
244
240
  valid_data = Data::LocalDateTime.new(2009,1,1)
245
241
  valid_data.class.should == Data::LocalDateTime
246
242
  lambda { @result.valid_start_date = valid_data }.should_not raise_error(ArgumentError)
247
243
  end
248
-
244
+
249
245
  it "only accepts Data::LocalDateTime for valid_end_date" do
250
246
  invalid_data = 1
251
247
  invalid_data.class.should_not == Data::LocalDateTime
252
248
  lambda { @result.valid_end_date = invalid_data }.should raise_error(ArgumentError)
253
-
249
+
254
250
  valid_data = Data::LocalDateTime.new(2009,1,1)
255
251
  valid_data.class.should == Data::LocalDateTime
256
252
  lambda { @result.valid_end_date = valid_data }.should_not raise_error(ArgumentError)
257
253
  end
258
-
254
+
259
255
  it "sets valid_start_date and valid_end_date if given date" do
260
- forecast = Measurement::Result.new
256
+ forecast = Barometer::Measurement::Result.new
261
257
  forecast.valid_start_date.should be_nil
262
258
  forecast.valid_end_date.should be_nil
263
259
  date = Date.new(2009,05,05)
@@ -269,7 +265,7 @@ describe "Result Measurement" do
269
265
  forecast.valid_start_date.hour.should == 0
270
266
  forecast.valid_start_date.min.should == 0
271
267
  forecast.valid_start_date.sec.should == 0
272
-
268
+
273
269
  forecast.valid_end_date.should_not be_nil
274
270
  forecast.valid_end_date.year.should == date.year
275
271
  forecast.valid_end_date.month.should == date.month
@@ -278,119 +274,114 @@ describe "Result Measurement" do
278
274
  forecast.valid_end_date.min.should == 59
279
275
  forecast.valid_end_date.sec.should == 59
280
276
  end
281
-
277
+
282
278
  it "returns true if the valid_date range includes the given date" do
283
- forecast = Measurement::Result.new
279
+ forecast = Barometer::Measurement::Result.new
284
280
  forecast.date = Date.new(2009,05,05)
285
281
  forecast.for_datetime?(Data::LocalDateTime.new(2009,5,5,12,0,0)).should be_true
286
282
  end
287
-
283
+
288
284
  it "returns false if the valid_date range excludes the given date" do
289
- forecast = Measurement::Result.new
285
+ forecast = Barometer::Measurement::Result.new
290
286
  forecast.date = Date.new(2009,05,05)
291
287
  forecast.for_datetime?(Data::LocalDateTime.new(2009,5,4,12,0,0)).should be_false
292
288
  end
293
-
289
+
294
290
  it "only accepts Fixnum or Float for humidity" do
295
291
  invalid_data = "invalid"
296
292
  invalid_data.class.should_not == Fixnum
297
293
  invalid_data.class.should_not == Float
298
294
  lambda { @result.humidity = invalid_data }.should raise_error(ArgumentError)
299
-
295
+
300
296
  valid_data = 1.to_i
301
297
  valid_data.class.should == Fixnum
302
298
  lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
303
-
299
+
304
300
  valid_data = 1.0.to_f
305
301
  valid_data.class.should == Float
306
302
  lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
307
303
  end
308
-
304
+
309
305
  it "only accepts String for icon" do
310
306
  invalid_data = 1
311
307
  invalid_data.class.should_not == String
312
308
  lambda { @result.icon = invalid_data }.should raise_error(ArgumentError)
313
-
309
+
314
310
  valid_data = "valid"
315
311
  valid_data.class.should == String
316
312
  lambda { @result.icon = valid_data }.should_not raise_error(ArgumentError)
317
313
  end
318
-
314
+
319
315
  it "only accepts String for condition" do
320
316
  invalid_data = 1
321
317
  invalid_data.class.should_not == String
322
318
  lambda { @result.condition = invalid_data }.should raise_error(ArgumentError)
323
-
319
+
324
320
  valid_data = "valid"
325
321
  valid_data.class.should == String
326
322
  lambda { @result.condition = valid_data }.should_not raise_error(ArgumentError)
327
323
  end
328
-
324
+
329
325
  it "only accepts Data::Speed for wind" do
330
326
  invalid_data = 1
331
327
  invalid_data.class.should_not == Data::Speed
332
328
  lambda { @result.wind = invalid_data }.should raise_error(ArgumentError)
333
-
329
+
334
330
  valid_data = Data::Speed.new
335
331
  valid_data.class.should == Data::Speed
336
332
  lambda { @result.wind = valid_data }.should_not raise_error(ArgumentError)
337
333
  end
338
-
334
+
339
335
  it "only accepts Data::Sun for sun" do
340
336
  invalid_data = 1
341
337
  invalid_data.class.should_not == Data::Sun
342
338
  lambda { @result.sun = invalid_data }.should raise_error(ArgumentError)
343
-
339
+
344
340
  valid_data = Data::Sun.new
345
341
  valid_data.class.should == Data::Sun
346
342
  lambda { @result.sun = valid_data }.should_not raise_error(ArgumentError)
347
343
  end
348
-
349
344
  end
350
-
345
+
351
346
  describe "method missing" do
352
-
353
347
  before(:each) do
354
- @result = Measurement::Result.new
348
+ @result = Barometer::Measurement::Result.new
355
349
  end
356
-
350
+
357
351
  it "responds to method + ?" do
358
352
  valid_method = "humidity"
359
353
  @result.respond_to?(valid_method).should be_true
360
354
  lambda { @result.send(valid_method + "?") }.should_not raise_error(NoMethodError)
361
355
  end
362
-
356
+
363
357
  it "ignores non_method + ?" do
364
358
  invalid_method = "humid"
365
359
  @result.respond_to?(invalid_method).should be_false
366
360
  lambda { @result.send(invalid_method + "?") }.should raise_error(NoMethodError)
367
361
  end
368
-
362
+
369
363
  it "returns true if set" do
370
364
  @result.humidity = 10
371
365
  @result.humidity.should_not be_nil
372
366
  @result.humidity?.should be_true
373
367
  end
374
-
368
+
375
369
  it "returns false if not set" do
376
370
  @result.humidity.should be_nil
377
371
  @result.humidity?.should be_false
378
372
  end
379
-
380
373
  end
381
-
374
+
382
375
  describe "answer simple questions, like" do
383
-
384
376
  before(:each) do
385
- @result = Measurement::Result.new
377
+ @result = Barometer::Measurement::Result.new
386
378
  @result.temperature = Data::Temperature.new
387
379
  @result.temperature << 5
388
380
  @dew_point = Data::Temperature.new
389
381
  @dew_point << 10
390
382
  end
391
-
383
+
392
384
  describe "windy?" do
393
-
394
385
  before(:each) do
395
386
  @wind = Data::Speed.new
396
387
  @wind << 11
@@ -401,7 +392,7 @@ describe "Result Measurement" do
401
392
  lambda { @result.windy? }.should_not raise_error(ArgumentError)
402
393
  lambda { @result.windy?(10) }.should_not raise_error(ArgumentError)
403
394
  end
404
-
395
+
405
396
  it "returns nil when no wind" do
406
397
  @result.wind?.should be_false
407
398
  @result.windy?.should be_nil
@@ -409,28 +400,26 @@ describe "Result Measurement" do
409
400
  @result.wind?.should be_true
410
401
  @result.windy?.should_not be_nil
411
402
  end
412
-
403
+
413
404
  it "return true when current wind over threshold" do
414
405
  @result.wind = @wind
415
406
  @result.windy?.should be_true
416
407
  @result.windy?(10).should be_true
417
408
  end
418
-
409
+
419
410
  it "return false when current wind under threshold" do
420
411
  @result.wind = @wind
421
412
  @result.windy?(15).should be_false
422
413
  end
423
-
424
414
  end
425
-
415
+
426
416
  describe "day?" do
427
-
428
417
  before(:each) do
429
418
  @early_time = Data::LocalTime.parse("6:00 am")
430
419
  @mid_time = Data::LocalTime.parse("11:00 am")
431
420
  @late_time = Data::LocalTime.parse("8:00 pm")
432
421
  @sun = Data::Sun.new(@early_time, @late_time)
433
-
422
+
434
423
  end
435
424
 
436
425
  it "requires Data::LocalTime object" do
@@ -439,7 +428,7 @@ describe "Result Measurement" do
439
428
  lambda { @result.day? }.should raise_error(ArgumentError)
440
429
  lambda { @result.day?(@mid_time) }.should_not raise_error(ArgumentError)
441
430
  end
442
-
431
+
443
432
  it "returns nil when no sun" do
444
433
  @result.sun?.should be_false
445
434
  @result.day?(@mid_time).should be_nil
@@ -447,28 +436,25 @@ describe "Result Measurement" do
447
436
  @result.sun?.should be_true
448
437
  @result.day?(@mid_time).should_not be_nil
449
438
  end
450
-
439
+
451
440
  it "return true when time between rise and set" do
452
441
  @result.sun = @sun
453
442
  @result.day?(@mid_time).should be_true
454
443
  end
455
-
444
+
456
445
  it "return false when time before rise or after set" do
457
446
  sun = Data::Sun.new(@mid_time, @late_time)
458
447
  @result.sun = sun
459
448
  @result.day?(@early_time).should be_false
460
-
449
+
461
450
  sun = Data::Sun.new(@early_time, @mid_time)
462
451
  @result.sun = sun
463
452
  @result.day?(@late_time).should be_false
464
453
  end
465
-
466
454
  end
467
-
455
+
468
456
  describe "wet?" do
469
-
470
457
  describe "wet_by_humidity?" do
471
-
472
458
  it "requires real threshold number (or nil)" do
473
459
  lambda { @result.send("_wet_by_humidity?","invalid") }.should raise_error(ArgumentError)
474
460
  lambda { @result.send("_wet_by_humidity?") }.should_not raise_error(ArgumentError)
@@ -497,11 +483,9 @@ describe "Result Measurement" do
497
483
  @result.send("_wet_by_humidity?",99).should be_false
498
484
  @result.wet?(nil,99).should be_false
499
485
  end
500
-
501
486
  end
502
-
487
+
503
488
  describe "wet_by_icon?" do
504
-
505
489
  before(:each) do
506
490
  @wet_icons = %w(rain thunderstorm)
507
491
  end
@@ -534,11 +518,9 @@ describe "Result Measurement" do
534
518
  @result.send("_wet_by_icon?",@wet_icons).should be_false
535
519
  @result.wet?(@wet_icons).should be_false
536
520
  end
537
-
538
521
  end
539
-
522
+
540
523
  describe "wet_by_dewpoint?" do
541
-
542
524
  it "returns nil when no dewpoint" do
543
525
  @result.dew_point?.should be_false
544
526
  @result.send("_wet_by_dewpoint?").should be_nil
@@ -561,11 +543,9 @@ describe "Result Measurement" do
561
543
  @result.send("_wet_by_dewpoint?").should be_false
562
544
  @result.wet?.should be_false
563
545
  end
564
-
565
546
  end
566
-
547
+
567
548
  describe "wet_by_pop?" do
568
-
569
549
  it "requires real threshold number (or nil)" do
570
550
  lambda { @result.send("_wet_by_pop?","invalid") }.should raise_error(ArgumentError)
571
551
  lambda { @result.send("_wet_by_pop?") }.should_not raise_error(ArgumentError)
@@ -593,22 +573,18 @@ describe "Result Measurement" do
593
573
  @result.send("_wet_by_pop?",50).should be_false
594
574
  @result.wet?.should be_false
595
575
  end
596
-
597
576
  end
598
-
599
577
  end
600
-
578
+
601
579
  describe "sunny?" do
602
-
603
580
  describe "sunny_by_icon?" do
604
-
605
581
  before(:each) do
606
582
  @sunny_icons = %w(sunny clear)
607
583
  @early_time = Data::LocalTime.parse("6:00 am")
608
584
  @mid_time = Data::LocalTime.parse("11:00 am")
609
585
  @late_time = Data::LocalTime.parse("8:00 pm")
610
586
  @sun = Data::Sun.new(@early_time, @late_time)
611
-
587
+
612
588
  @result.sun = @sun
613
589
  end
614
590
 
@@ -640,21 +616,17 @@ describe "Result Measurement" do
640
616
  @result.send("_sunny_by_icon?",@sunny_icons).should be_false
641
617
  @result.sunny?(@mid_time,@sunny_icons).should be_false
642
618
  end
643
-
619
+
644
620
  it "returns false when night" do
645
621
  @result.icon = "sunny"
646
622
  @result.send("_sunny_by_icon?",@sunny_icons).should be_true
647
623
  @result.sunny?(@mid_time,@sunny_icons).should be_true
648
-
624
+
649
625
  @sun = Data::Sun.new(@mid_time, @late_time)
650
626
  @result.sun = @sun
651
627
  @result.sunny?(@early_time,@sunny_icons).should be_false
652
628
  end
653
-
654
629
  end
655
-
656
630
  end
657
-
658
631
  end
659
-
660
- end
632
+ end