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,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::LocalDateTime" do
4
-
4
+
5
5
  before(:each) do
6
6
  @y = 2009
7
7
  @mon = 5
@@ -10,45 +10,45 @@ describe "Data::LocalDateTime" do
10
10
  @m = 11
11
11
  @s = 10
12
12
  end
13
-
13
+
14
14
  describe "when initialized" do
15
-
15
+
16
16
  before(:each) do
17
17
  @datetime = Data::LocalDateTime.new(@y,@mon,@d)
18
18
  end
19
-
19
+
20
20
  it "responds to hour" do
21
21
  @datetime.hour.should == 0
22
22
  end
23
-
23
+
24
24
  it "responds to min" do
25
25
  @datetime.min.should == 0
26
26
  end
27
-
27
+
28
28
  it "responds to sec" do
29
29
  @datetime.sec.should == 0
30
30
  end
31
-
31
+
32
32
  it "responds to year" do
33
33
  @datetime.year.should == @y
34
34
  end
35
-
35
+
36
36
  it "responds to month" do
37
37
  @datetime.month.should == @mon
38
38
  end
39
-
39
+
40
40
  it "responds to day" do
41
41
  @datetime.day.should == @d
42
42
  end
43
-
43
+
44
44
  end
45
-
45
+
46
46
  describe "conversion" do
47
-
47
+
48
48
  before(:each) do
49
49
  @datetime = Data::LocalDateTime.new(@y,@mon,@d,@h,@m,@s)
50
50
  end
51
-
51
+
52
52
  it "converts to a DateTime object" do
53
53
  @datetime.is_a?(Data::LocalDateTime)
54
54
  datetime = @datetime.to_dt
@@ -60,7 +60,7 @@ describe "Data::LocalDateTime" do
60
60
  datetime.min.should == @m
61
61
  datetime.sec.should == @s
62
62
  end
63
-
63
+
64
64
  it "converts to a Date object" do
65
65
  @datetime.is_a?(Data::LocalDateTime)
66
66
  date = @datetime.to_d
@@ -80,9 +80,9 @@ describe "Data::LocalDateTime" do
80
80
  end
81
81
 
82
82
  end
83
-
83
+
84
84
  describe "parsing" do
85
-
85
+
86
86
  before(:each) do
87
87
  @y = 2009
88
88
  @mon = 5
@@ -92,7 +92,7 @@ describe "Data::LocalDateTime" do
92
92
  @s = 10
93
93
  @datetime = Data::LocalDateTime.new(@y,@mon,@d,@h,@m,@s)
94
94
  end
95
-
95
+
96
96
  it "parses a Time object" do
97
97
  time = Time.local(@y,@mon,@d,@h,@m,@s)
98
98
  @datetime.parse(time)
@@ -103,7 +103,7 @@ describe "Data::LocalDateTime" do
103
103
  @datetime.min.should == @m
104
104
  @datetime.sec.should == @s
105
105
  end
106
-
106
+
107
107
  it "parses a DateTime object" do
108
108
  datetime = DateTime.new(@y,@mon,@d,@h,@m,@s)
109
109
  @datetime.parse(datetime)
@@ -114,7 +114,7 @@ describe "Data::LocalDateTime" do
114
114
  @datetime.min.should == @m
115
115
  @datetime.sec.should == @s
116
116
  end
117
-
117
+
118
118
  it "parses a Date object" do
119
119
  date = Date.civil(@y,@mon,@d)
120
120
  @datetime.parse(date)
@@ -122,7 +122,7 @@ describe "Data::LocalDateTime" do
122
122
  @datetime.month.should == @mon
123
123
  @datetime.day.should == @d
124
124
  end
125
-
125
+
126
126
  it "parses a String" do
127
127
  string = "#{@y}-#{@mon}-#{@d} #{@h}:#{@m}:#{@s}"
128
128
  @datetime.parse(string)
@@ -133,7 +133,7 @@ describe "Data::LocalDateTime" do
133
133
  @datetime.min.should == @m
134
134
  @datetime.sec.should == @s
135
135
  end
136
-
136
+
137
137
  it "parses a String (using class method)" do
138
138
  string = "#{@y}-#{@mon}-#{@d} #{@h}:#{@m}:#{@s}"
139
139
  datetime = Data::LocalDateTime.parse(string)
@@ -151,13 +151,13 @@ describe "Data::LocalDateTime" do
151
151
  datetime.should be_nil
152
152
  end
153
153
  end
154
-
154
+
155
155
  describe "storing" do
156
-
156
+
157
157
  before(:each) do
158
158
  @datetime = Data::LocalDateTime.new(@y,@mon,@d,@h,@m,@s)
159
159
  end
160
-
160
+
161
161
  it "requires Fixnum (accepts nil)" do
162
162
  invalid_data = "s"
163
163
  valid_data = 1
@@ -171,104 +171,104 @@ describe "Data::LocalDateTime" do
171
171
  lambda { @datetime.day = valid_data }.should_not raise_error(ArgumentError)
172
172
  lambda { @datetime.day = nil }.should raise_error(ArgumentError)
173
173
  end
174
-
174
+
175
175
  it "rejects invalid dates during init" do
176
176
  lambda { Data::LocalDateTime.new(2009,0,1) }.should raise_error(ArgumentError)
177
177
  lambda { Data::LocalDateTime.new(2009,1,0) }.should raise_error(ArgumentError)
178
178
  lambda { Data::LocalDateTime.new(2009,13,1) }.should raise_error(ArgumentError)
179
179
  lambda { Data::LocalDateTime.new(2009,1,32) }.should raise_error(ArgumentError)
180
180
  end
181
-
181
+
182
182
  it "rejects invalid days" do
183
183
  lambda { @datetime.day = nil }.should raise_error(ArgumentError)
184
184
  lambda { @datetime.day = 32 }.should raise_error(ArgumentError)
185
185
  lambda { @datetime.day = "a" }.should raise_error(ArgumentError)
186
186
  lambda { @datetime.day = 0 }.should raise_error(ArgumentError)
187
187
  end
188
-
188
+
189
189
  it "rejects invalid months" do
190
190
  lambda { @datetime.month = nil }.should raise_error(ArgumentError)
191
191
  lambda { @datetime.month = 32 }.should raise_error(ArgumentError)
192
192
  lambda { @datetime.month = "a" }.should raise_error(ArgumentError)
193
193
  lambda { @datetime.month = 0 }.should raise_error(ArgumentError)
194
194
  end
195
-
195
+
196
196
  it "rejects invalid years" do
197
197
  lambda { @datetime.year = nil }.should raise_error(ArgumentError)
198
198
  lambda { @datetime.year = "a" }.should raise_error(ArgumentError)
199
199
  end
200
-
200
+
201
201
  end
202
-
202
+
203
203
  describe "retrieving" do
204
-
204
+
205
205
  before(:each) do
206
206
  @datetime = Data::LocalDateTime.new(@y,@mon,@d,@h,@m,@s)
207
207
  end
208
-
208
+
209
209
  it "returns pretty string" do
210
210
  @datetime.to_s.should == "2009-05-01"
211
211
  @datetime.to_s(true).should == "2009-05-01 12:11:10 pm"
212
212
  end
213
-
213
+
214
214
  end
215
-
215
+
216
216
  describe "comparators" do
217
-
217
+
218
218
  before(:each) do
219
219
  @datetime_low = Data::LocalDateTime.new(2009,5,4,0,0,1)
220
220
  @datetime_mid = Data::LocalDateTime.new(2009,5,5,12,0,0)
221
221
  @datetime_high = Data::LocalDateTime.new(2009,5,6,23,59,59)
222
222
  end
223
-
223
+
224
224
  it "counts days" do
225
225
  Data::LocalDateTime.new(0,1,1,0,0,0)._total_days.should == 1
226
226
  Data::LocalDateTime.new(0,2,1,0,0,0)._total_days.should == 32
227
227
  Data::LocalDateTime.new(1,1,1,0,0,0)._total_days.should == 367
228
228
  end
229
-
229
+
230
230
  it "defines <=>" do
231
231
  Data::LocalDateTime.method_defined?("<=>").should be_true
232
232
  (@datetime_low <=> @datetime_high).should == -1
233
233
  (@datetime_high <=> @datetime_low).should == 1
234
234
  (@datetime_mid <=> @datetime_mid).should == 0
235
235
  end
236
-
236
+
237
237
  it "compares to a Time object" do
238
238
  time = Time.local(2009,5,5,12,0,0)
239
239
  (@datetime_low <=> time).should == -1
240
240
  (@datetime_high <=> time).should == 1
241
241
  (@datetime_mid <=> time).should == 0
242
242
  end
243
-
243
+
244
244
  it "compares to a DateTime object" do
245
245
  time = DateTime.new(2009,5,5,12,0,0)
246
246
  (@datetime_low <=> time).should == -1
247
247
  (@datetime_high <=> time).should == 1
248
248
  (@datetime_mid <=> time).should == 0
249
249
  end
250
-
250
+
251
251
  it "compares to a Date object" do
252
252
  date = Date.civil(2009,5,5)
253
253
  (@datetime_low <=> date).should == -1
254
254
  (@datetime_high <=> date).should == 1
255
255
  (@datetime_mid <=> date).should == 0
256
256
  end
257
-
257
+
258
258
  it "compares to a String object" do
259
259
  time = "2009-5-5 12:00:00"
260
260
  (@datetime_low <=> time).should == -1
261
261
  (@datetime_high <=> time).should == 1
262
262
  (@datetime_mid <=> time).should == 0
263
263
  end
264
-
264
+
265
265
  it "compares to a Data::LocalTime object" do
266
266
  local_time = Data::LocalTime.new(12,0,0)
267
267
  (@datetime_low <=> local_time).should == -1
268
268
  (@datetime_high <=> local_time).should == 1
269
269
  (@datetime_mid <=> local_time).should == 0
270
270
  end
271
-
271
+
272
272
  end
273
-
273
+
274
274
  end
@@ -1,36 +1,36 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Data::LocalTime" do
4
-
4
+
5
5
  describe "when initialized" do
6
-
6
+
7
7
  before(:each) do
8
8
  @time = Data::LocalTime.new
9
9
  end
10
-
10
+
11
11
  it "responds to hour" do
12
12
  @time.hour.should == 0
13
13
  end
14
-
14
+
15
15
  it "responds to min" do
16
16
  @time.min.should == 0
17
17
  end
18
-
18
+
19
19
  it "responds to sec" do
20
20
  @time.sec.should == 0
21
21
  end
22
-
22
+
23
23
  end
24
-
24
+
25
25
  describe "conversion" do
26
-
26
+
27
27
  before(:each) do
28
28
  @h = 12
29
29
  @m = 11
30
30
  @s = 10
31
31
  @time = Data::LocalTime.new(@h,@m,@s)
32
32
  end
33
-
33
+
34
34
  it "converts to a Time object" do
35
35
  @time.is_a?(Data::LocalTime)
36
36
  @time.to_t.is_a?(Time).should be_true
@@ -38,18 +38,18 @@ describe "Data::LocalTime" do
38
38
  @time.min.should == @m
39
39
  @time.sec.should == @s
40
40
  end
41
-
41
+
42
42
  end
43
-
43
+
44
44
  describe "parsing" do
45
-
45
+
46
46
  before(:each) do
47
47
  @h = 12
48
48
  @m = 11
49
49
  @s = 10
50
50
  @time = Data::LocalTime.new(@h,@m,@s)
51
51
  end
52
-
52
+
53
53
  it "parses a Time object" do
54
54
  time = Time.local(2009,1,1,@h,@m,@s)
55
55
  @time.parse(time)
@@ -57,7 +57,7 @@ describe "Data::LocalTime" do
57
57
  @time.min.should == @m
58
58
  @time.sec.should == @s
59
59
  end
60
-
60
+
61
61
  it "parses a DateTime object" do
62
62
  time = DateTime.new(2009,1,1,@h,@m,@s)
63
63
  @time.parse(time)
@@ -65,7 +65,7 @@ describe "Data::LocalTime" do
65
65
  @time.min.should == @m
66
66
  @time.sec.should == @s
67
67
  end
68
-
68
+
69
69
  it "parses a String" do
70
70
  time = "#{@h}:#{@m}:#{@s}"
71
71
  @time.parse(time)
@@ -73,7 +73,7 @@ describe "Data::LocalTime" do
73
73
  @time.min.should == @m
74
74
  @time.sec.should == @s
75
75
  end
76
-
76
+
77
77
  it "parses a String (using class method)" do
78
78
  time = "#{@h}:#{@m}:#{@s}"
79
79
  time = Data::LocalTime.parse(time)
@@ -81,18 +81,18 @@ describe "Data::LocalTime" do
81
81
  time.min.should == @m
82
82
  time.sec.should == @s
83
83
  end
84
-
84
+
85
85
  end
86
-
86
+
87
87
  describe "storing" do
88
-
88
+
89
89
  before(:each) do
90
90
  @h = 12
91
91
  @m = 11
92
92
  @s = 10
93
93
  @time = Data::LocalTime.new(@h,@m,@s)
94
94
  end
95
-
95
+
96
96
  it "requires Fixnum (accepts nil)" do
97
97
  invalid_data = "s"
98
98
  valid_data = 1
@@ -106,104 +106,104 @@ describe "Data::LocalTime" do
106
106
  lambda { @time.sec = valid_data }.should_not raise_error(ArgumentError)
107
107
  lambda { @time.sec = nil }.should_not raise_error(ArgumentError)
108
108
  end
109
-
109
+
110
110
  it "rolls over seconds" do
111
111
  time = Data::LocalTime.new(0,0,60)
112
112
  time.sec.should == 0
113
113
  time.min.should == 1
114
114
  end
115
-
115
+
116
116
  it "rolls over minutes" do
117
117
  time = Data::LocalTime.new(0,60,0)
118
118
  time.min.should == 0
119
119
  time.hour.should == 1
120
120
  end
121
-
121
+
122
122
  it "rolls over hours" do
123
123
  time = Data::LocalTime.new(24,0,0)
124
124
  time.sec.should == 0
125
125
  time.min.should == 0
126
126
  time.hour.should == 0
127
127
  end
128
-
128
+
129
129
  it "rolls over everything" do
130
130
  time = Data::LocalTime.new(50,600,601)
131
131
  time.sec.should == 1
132
132
  time.min.should == 10
133
133
  time.hour.should == 12
134
134
  end
135
-
135
+
136
136
  it "add seconds" do
137
137
  time = Data::LocalTime.new(0,0,0)
138
138
  time = time + 61
139
139
  time.sec.should == 1
140
140
  time.min.should == 1
141
141
  end
142
-
142
+
143
143
  end
144
-
144
+
145
145
  describe "retrieving" do
146
-
146
+
147
147
  before(:each) do
148
148
  @h = 6
149
149
  @m = 30
150
150
  @s = 20
151
151
  @time = Data::LocalTime.new(@h,@m,@s)
152
152
  end
153
-
153
+
154
154
  it "returns pretty string" do
155
155
  @time.to_s.should == "06:30 am"
156
156
  @time.to_s(true).should == "06:30:20 am"
157
157
  end
158
-
158
+
159
159
  end
160
-
160
+
161
161
  describe "comparators" do
162
-
162
+
163
163
  before(:each) do
164
164
  @time_low = Data::LocalTime.new(0,0,1)
165
165
  @time_mid = Data::LocalTime.new(12,0,0)
166
166
  @time_high = Data::LocalTime.new(23,59,59)
167
167
  end
168
-
168
+
169
169
  it "defines <=>" do
170
170
  Data::LocalTime.method_defined?("<=>").should be_true
171
171
  (@time_low <=> @time_high).should == -1
172
172
  (@time_high <=> @time_low).should == 1
173
173
  (@time_mid <=> @time_mid).should == 0
174
174
  end
175
-
175
+
176
176
  it "compares to a Time object" do
177
177
  time = Time.local(2009,1,1,12,0,0)
178
178
  (@time_low <=> time).should == -1
179
179
  (@time_high <=> time).should == 1
180
180
  (@time_mid <=> time).should == 0
181
181
  end
182
-
182
+
183
183
  it "compares to a DateTime object" do
184
184
  time = DateTime.new(2009,1,1,12,0,0)
185
185
  (@time_low <=> time).should == -1
186
186
  (@time_high <=> time).should == 1
187
187
  (@time_mid <=> time).should == 0
188
188
  end
189
-
189
+
190
190
  it "compares to a String object" do
191
191
  time = "12:00:00"
192
192
  (@time_low <=> time).should == -1
193
193
  (@time_high <=> time).should == 1
194
194
  (@time_mid <=> time).should == 0
195
195
  end
196
-
196
+
197
197
  end
198
-
198
+
199
199
  describe "math" do
200
-
200
+
201
201
  it "counts the total seconds" do
202
202
  Data::LocalTime.new(0,0,1).total_seconds.should == 1
203
203
  Data::LocalTime.new(0,1,0).total_seconds.should == (1*60)
204
204
  Data::LocalTime.new(1,0,0).total_seconds.should == (1*60*60)
205
205
  end
206
-
206
+
207
207
  it "provides a difference" do
208
208
  a = Data::LocalTime.new(0,0,1)
209
209
  b = Data::LocalTime.new(1,0,0)
@@ -211,29 +211,29 @@ describe "Data::LocalTime" do
211
211
  a.diff(b).should == diff
212
212
  b.diff(a).should == diff
213
213
  end
214
-
214
+
215
215
  it "adds time" do
216
216
  a = Data::LocalTime.new(0,0,1)
217
217
  b = Data::LocalTime.new(1,0,0)
218
218
  c = (a + b)
219
219
  c.is_a?(Data::LocalTime).should be_true
220
220
  c.should == Data::LocalTime.new(1,0,1)
221
-
221
+
222
222
  b = Data::LocalTime.new(1,0,0)
223
223
  (b + 1).should == Data::LocalTime.new(1,0,1)
224
224
  end
225
-
225
+
226
226
  it "subtracts time" do
227
227
  a = Data::LocalTime.new(0,0,1)
228
228
  b = Data::LocalTime.new(1,0,0)
229
229
  c = (b - a)
230
230
  c.is_a?(Data::LocalTime).should be_true
231
231
  c.should == Data::LocalTime.new(0,59,59)
232
-
232
+
233
233
  b = Data::LocalTime.new(1,0,0)
234
234
  (b - 1).should == Data::LocalTime.new(0,59,59)
235
235
  end
236
-
236
+
237
237
  end
238
-
239
- end
238
+
239
+ end