acts_as_flux_capacitor 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.6.1 2008-05-24
2
+
3
+ * Cleanup, get rid of excess methods, ie within? (thanks to nick ang again!)
4
+ * Added specs for core class extensions
5
+
1
6
  == 0.6.0 2008-05-23
2
7
 
3
8
  * WAAAY more hardcore spec'ng
@@ -280,7 +280,6 @@ private
280
280
 
281
281
  module CompareEvents
282
282
  def overlaps_with?(other_event)
283
- #this method possesses the associative property.
284
283
  self.to_range.overlaps?(other_event.to_range)
285
284
  end
286
285
 
@@ -289,10 +288,8 @@ private
289
288
  end
290
289
  alias overlap overlap_with
291
290
 
292
- def back_to_back_with?(other_event,tolerance = 0)
291
+ def back_to_back_with?(other_event,tolerance = 2.seconds)
293
292
  # tolerance is in seconds.
294
- # first_event,second_event = self.class.send(:ordered_tuple,self,other_event)
295
- # first_event.ends_at.approx_eql?(second_event.begins_at,tolerance)
296
293
  self.start_time.before?(other_event.start_time) ? first_to_start = self : first_to_start = other_event
297
294
  first_to_start.ends_at.approx_eql?(other_event.begins_at,tolerance)
298
295
  end
@@ -10,26 +10,9 @@ class Time
10
10
  @@approx_eql_tolerance_in_seconds = seconds
11
11
  end
12
12
 
13
- def approx_eql?(other_time,tolerance = @@approx_eql_tolerance_in_seconds)
13
+ def approx_eql? other_time,tolerance = @@approx_eql_tolerance_in_seconds
14
14
  times_to_i = [self,other_time].collect { |time| time.to_i }
15
- times_to_i.within?(tolerance)
16
- end
17
- end
18
-
19
- class Array
20
- def within? tolerance
21
-
22
- # thanks, nick ang!
23
- unless self.size == 2
24
- raise ArgumentError <<ERROR_STRING
25
- within? only works with arrays of two numbers. do something like
26
- ([a,b,c].max,[a,b,c].min).within?(tolerance) as an implementation
27
- for an array with more than two values
28
- ERROR_STRING
29
- end
30
-
31
- difference = self.first - self.last
32
- difference.abs <= tolerance
15
+ (self - other_time).abs < tolerance
33
16
  end
34
17
  end
35
18
 
@@ -5,7 +5,7 @@ module HolmesLabs #:nodoc:
5
5
 
6
6
  MAJOR = 0
7
7
  MINOR = 6
8
- TINY = 0
8
+ TINY = 1
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY].join('.')
11
11
 
@@ -109,8 +109,6 @@ describe "The class TimePeriod < ActiveRecord::Base" do
109
109
  end
110
110
 
111
111
  describe "The TimePeriod.find extensions" do
112
-
113
- include TimePeriodFixtures
114
112
 
115
113
  it "should find time_periods in the present" do
116
114
  TimePeriod.find(:first,:present=>true ,:current_time => present_time).
@@ -171,8 +169,6 @@ describe "The TimePeriod.find extensions" do
171
169
  end
172
170
 
173
171
  describe "The TimePeriod comparison helpers" do
174
-
175
- include TimePeriodFixtures
176
172
 
177
173
  it "should determine if one time period is before another" do
178
174
  present_period.before_or_at?(future_period).should be_true
@@ -201,6 +197,11 @@ describe "The TimePeriod comparison helpers" do
201
197
  it "should determine if two time_periods are back-to-back" do
202
198
  long_period.back_to_back_with?(future_period).should be_false
203
199
  past_period.back_to_back_with?(present_period).should be_true
200
+
201
+ long_period.back_to_back_with?(future_period,1.minute).should be_false
202
+ past_period.back_to_back_with?(present_period,1.minute).should be_true
203
+
204
+ long_period.back_to_back_with?(future_period,50.years).should be_true
204
205
  end
205
206
 
206
207
  it "should determine if a time_period is between two other time_periods" do
@@ -355,3 +356,26 @@ describe "The Range overlap helpers" do
355
356
  end
356
357
 
357
358
  end
359
+
360
+ describe "The extensions to" do
361
+
362
+ describe "the Time class" do
363
+
364
+ it "should determine if two times are approximately equal (tolerance @ 1 second)" do
365
+ Time.freeze do
366
+ Time.now.approx_eql?(Time.now+(0.5).seconds,1.second).should be_true
367
+ Time.now.approx_eql?(Time.now+10.seconds,1.second).should be_false
368
+ (Time.now+(0.5).seconds).approx_eql?(Time.now,1.second).should be_true
369
+ (Time.now+10.seconds).approx_eql?(Time.now,1.second).should be_false
370
+ end
371
+ end
372
+
373
+ it "should determine if two times are approximately equal (tolerance @ 0.1 seconds)" do
374
+ Time.freeze do
375
+ Time.now.approx_eql?(Time.now+(0.01).seconds,(0.1).seconds).should be_true
376
+ Time.now.approx_eql?(Time.now+10.seconds,(0.1).seconds).should be_false
377
+ end
378
+ end
379
+ end
380
+ end
381
+
data/spec/report.html CHANGED
@@ -179,116 +179,125 @@ a {
179
179
  <div class="example_group">
180
180
  <dl>
181
181
  <dt id="example_group_1">The Temporal mixin</dt>
182
- <script type="text/javascript">moveProgressBar('2.6');</script>
182
+ <script type="text/javascript">moveProgressBar('2.5');</script>
183
183
  <dd class="spec passed"><span class="passed_spec_name">should make Time, Date and DateTime into Temporal objects</span></dd>
184
- <script type="text/javascript">moveProgressBar('5.2');</script>
184
+ <script type="text/javascript">moveProgressBar('5.0');</script>
185
185
  <dd class="spec passed"><span class="passed_spec_name">should determine the length of time between two Temporal objects</span></dd>
186
- <script type="text/javascript">moveProgressBar('7.8');</script>
186
+ <script type="text/javascript">moveProgressBar('7.5');</script>
187
187
  <dd class="spec passed"><span class="passed_spec_name">should determine the length of time until a Temporal object</span></dd>
188
- <script type="text/javascript">moveProgressBar('10.5');</script>
188
+ <script type="text/javascript">moveProgressBar('10.0');</script>
189
189
  <dd class="spec passed"><span class="passed_spec_name">should determine if a temporal object is in the future</span></dd>
190
- <script type="text/javascript">moveProgressBar('13.1');</script>
190
+ <script type="text/javascript">moveProgressBar('12.5');</script>
191
191
  <dd class="spec passed"><span class="passed_spec_name">should determine the length of time since a Temporal object</span></dd>
192
- <script type="text/javascript">moveProgressBar('15.7');</script>
192
+ <script type="text/javascript">moveProgressBar('15.0');</script>
193
193
  <dd class="spec passed"><span class="passed_spec_name">should determine if a temporal object is in the past</span></dd>
194
- <script type="text/javascript">moveProgressBar('18.4');</script>
194
+ <script type="text/javascript">moveProgressBar('17.5');</script>
195
195
  <dd class="spec passed"><span class="passed_spec_name">should determine if one Temporal object is before another</span></dd>
196
- <script type="text/javascript">moveProgressBar('21.0');</script>
196
+ <script type="text/javascript">moveProgressBar('20.0');</script>
197
197
  <dd class="spec passed"><span class="passed_spec_name">should determine if one Temporal object is after another</span></dd>
198
198
  </dl>
199
199
  </div>
200
200
  <div class="example_group">
201
201
  <dl>
202
202
  <dt id="example_group_2">The class TimePeriod &lt; ActiveRecord::Base</dt>
203
- <script type="text/javascript">moveProgressBar('23.6');</script>
203
+ <script type="text/javascript">moveProgressBar('22.5');</script>
204
204
  <dd class="spec passed"><span class="passed_spec_name">should be a flux capacitor</span></dd>
205
- <script type="text/javascript">moveProgressBar('26.3');</script>
205
+ <script type="text/javascript">moveProgressBar('25.0');</script>
206
206
  <dd class="spec passed"><span class="passed_spec_name">should be a Temporal object</span></dd>
207
- <script type="text/javascript">moveProgressBar('28.9');</script>
207
+ <script type="text/javascript">moveProgressBar('27.5');</script>
208
208
  <dd class="spec passed"><span class="passed_spec_name">should possess all four bitemporal database attributes</span></dd>
209
- <script type="text/javascript">moveProgressBar('31.5');</script>
209
+ <script type="text/javascript">moveProgressBar('30.0');</script>
210
210
  <dd class="spec passed"><span class="passed_spec_name">should not be valid if either of the two time spans are 0 or less</span></dd>
211
211
  </dl>
212
212
  </div>
213
213
  <div class="example_group">
214
214
  <dl>
215
215
  <dt id="example_group_3">The TimePeriod.find extensions</dt>
216
- <script type="text/javascript">moveProgressBar('34.2');</script>
216
+ <script type="text/javascript">moveProgressBar('32.5');</script>
217
217
  <dd class="spec passed"><span class="passed_spec_name">should find time_periods in the present</span></dd>
218
- <script type="text/javascript">moveProgressBar('36.8');</script>
218
+ <script type="text/javascript">moveProgressBar('35.0');</script>
219
219
  <dd class="spec passed"><span class="passed_spec_name">should find time_periods in the past</span></dd>
220
- <script type="text/javascript">moveProgressBar('39.4');</script>
220
+ <script type="text/javascript">moveProgressBar('37.5');</script>
221
221
  <dd class="spec passed"><span class="passed_spec_name">should find time_periods in the future</span></dd>
222
- <script type="text/javascript">moveProgressBar('42.1');</script>
222
+ <script type="text/javascript">moveProgressBar('40.0');</script>
223
223
  <dd class="spec passed"><span class="passed_spec_name">should find time_periods occuring at a specific time</span></dd>
224
- <script type="text/javascript">moveProgressBar('44.7');</script>
224
+ <script type="text/javascript">moveProgressBar('42.5');</script>
225
225
  <dd class="spec passed"><span class="passed_spec_name">should find time_periods occuring within a specific range of time</span></dd>
226
226
  </dl>
227
227
  </div>
228
228
  <div class="example_group">
229
229
  <dl>
230
230
  <dt id="example_group_4">The TimePeriod comparison helpers</dt>
231
- <script type="text/javascript">moveProgressBar('47.3');</script>
231
+ <script type="text/javascript">moveProgressBar('45.0');</script>
232
232
  <dd class="spec passed"><span class="passed_spec_name">should determine if one time period is before another</span></dd>
233
- <script type="text/javascript">moveProgressBar('50.0');</script>
233
+ <script type="text/javascript">moveProgressBar('47.5');</script>
234
234
  <dd class="spec passed"><span class="passed_spec_name">should determine if one time period is after another</span></dd>
235
- <script type="text/javascript">moveProgressBar('52.6');</script>
235
+ <script type="text/javascript">moveProgressBar('50.0');</script>
236
236
  <dd class="spec passed"><span class="passed_spec_name">should calculate the time between time_periods</span></dd>
237
- <script type="text/javascript">moveProgressBar('55.2');</script>
237
+ <script type="text/javascript">moveProgressBar('52.5');</script>
238
238
  <dd class="spec passed"><span class="passed_spec_name">should determine whether two time_periods overlap</span></dd>
239
- <script type="text/javascript">moveProgressBar('57.8');</script>
239
+ <script type="text/javascript">moveProgressBar('55.0');</script>
240
240
  <dd class="spec passed"><span class="passed_spec_name">should determine the length of time by which two time_periods overlap</span></dd>
241
- <script type="text/javascript">moveProgressBar('60.5');</script>
241
+ <script type="text/javascript">moveProgressBar('57.5');</script>
242
242
  <dd class="spec passed"><span class="passed_spec_name">should determine if two time_periods are back-to-back</span></dd>
243
- <script type="text/javascript">moveProgressBar('63.1');</script>
243
+ <script type="text/javascript">moveProgressBar('60.0');</script>
244
244
  <dd class="spec passed"><span class="passed_spec_name">should determine if a time_period is between two other time_periods</span></dd>
245
245
  </dl>
246
246
  </div>
247
247
  <div class="example_group">
248
248
  <dl>
249
249
  <dt id="example_group_5">The TimePeriod status helpers</dt>
250
- <script type="text/javascript">moveProgressBar('65.7');</script>
250
+ <script type="text/javascript">moveProgressBar('62.5');</script>
251
251
  <dd class="spec passed"><span class="passed_spec_name">should determine the length of time until a time_period</span></dd>
252
- <script type="text/javascript">moveProgressBar('68.4');</script>
252
+ <script type="text/javascript">moveProgressBar('65.0');</script>
253
253
  <dd class="spec passed"><span class="passed_spec_name">should determine if a time_period is in the future</span></dd>
254
- <script type="text/javascript">moveProgressBar('71.0');</script>
254
+ <script type="text/javascript">moveProgressBar('67.5');</script>
255
255
  <dd class="spec passed"><span class="passed_spec_name">should determine the length of time since a time_period ended</span></dd>
256
- <script type="text/javascript">moveProgressBar('73.6');</script>
256
+ <script type="text/javascript">moveProgressBar('70.0');</script>
257
257
  <dd class="spec passed"><span class="passed_spec_name">should determine if a time_period is in the past</span></dd>
258
- <script type="text/javascript">moveProgressBar('76.3');</script>
258
+ <script type="text/javascript">moveProgressBar('72.5');</script>
259
259
  <dd class="spec passed"><span class="passed_spec_name">should determine if a time_period has started</span></dd>
260
- <script type="text/javascript">moveProgressBar('78.9');</script>
260
+ <script type="text/javascript">moveProgressBar('75.0');</script>
261
261
  <dd class="spec passed"><span class="passed_spec_name">should determine how much time has elapsed since an event started</span></dd>
262
- <script type="text/javascript">moveProgressBar('81.5');</script>
262
+ <script type="text/javascript">moveProgressBar('77.5');</script>
263
263
  <dd class="spec passed"><span class="passed_spec_name">should determine what percentage of time has elapsed since an event started</span></dd>
264
- <script type="text/javascript">moveProgressBar('84.2');</script>
264
+ <script type="text/javascript">moveProgressBar('80.0');</script>
265
265
  <dd class="spec passed"><span class="passed_spec_name">should determine how much time is remaining until an event ends</span></dd>
266
- <script type="text/javascript">moveProgressBar('86.8');</script>
266
+ <script type="text/javascript">moveProgressBar('82.5');</script>
267
267
  <dd class="spec passed"><span class="passed_spec_name">should determine what percentage of time is remaining until an event ends</span></dd>
268
- <script type="text/javascript">moveProgressBar('89.4');</script>
268
+ <script type="text/javascript">moveProgressBar('85.0');</script>
269
269
  <dd class="spec passed"><span class="passed_spec_name">should determine if a time_period has ended</span></dd>
270
- <script type="text/javascript">moveProgressBar('92.1');</script>
270
+ <script type="text/javascript">moveProgressBar('87.5');</script>
271
271
  <dd class="spec passed"><span class="passed_spec_name">should determine the duration of a time_period</span></dd>
272
272
  </dl>
273
273
  </div>
274
274
  <div class="example_group">
275
275
  <dl>
276
276
  <dt id="example_group_6">The TimePeriod modification helpers</dt>
277
- <script type="text/javascript">moveProgressBar('94.7');</script>
277
+ <script type="text/javascript">moveProgressBar('90.0');</script>
278
278
  <dd class="spec passed"><span class="passed_spec_name">should shift a time_period into the past or future</span></dd>
279
279
  </dl>
280
280
  </div>
281
281
  <div class="example_group">
282
282
  <dl>
283
283
  <dt id="example_group_7">The Range overlap helpers</dt>
284
- <script type="text/javascript">moveProgressBar('97.3');</script>
284
+ <script type="text/javascript">moveProgressBar('92.5');</script>
285
285
  <dd class="spec passed"><span class="passed_spec_name">should determine if two ranges do not overlap</span></dd>
286
- <script type="text/javascript">moveProgressBar('100.0');</script>
286
+ <script type="text/javascript">moveProgressBar('95.0');</script>
287
287
  <dd class="spec passed"><span class="passed_spec_name">should determine if two ranges do overlap</span></dd>
288
288
  </dl>
289
289
  </div>
290
- <script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>0.368839 seconds</strong>";</script>
291
- <script type="text/javascript">document.getElementById('totals').innerHTML = "38 examples, 0 failures";</script>
290
+ <div class="example_group">
291
+ <dl>
292
+ <dt id="example_group_8">The extensions to the Time class</dt>
293
+ <script type="text/javascript">moveProgressBar('97.5');</script>
294
+ <dd class="spec passed"><span class="passed_spec_name">should determine if two times are approximately equal (tolerance @ 1 second)</span></dd>
295
+ <script type="text/javascript">moveProgressBar('100.0');</script>
296
+ <dd class="spec passed"><span class="passed_spec_name">should determine if two times are approximately equal (tolerance @ 0.1 seconds)</span></dd>
297
+ </dl>
298
+ </div>
299
+ <script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>0.476378 seconds</strong>";</script>
300
+ <script type="text/javascript">document.getElementById('totals').innerHTML = "40 examples, 0 failures";</script>
292
301
  </div>
293
302
  </div>
294
303
  </body>
data/spec/schema.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  ActiveRecord::Schema.define(:version => 1) do
2
2
 
3
3
  create_table "time_periods", :force => true do |t|
4
+
4
5
  t.string "contents"
6
+
5
7
  t.datetime "begins_at"
6
8
  t.datetime "ends_at"
7
9
  t.datetime "created_at"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_flux_capacitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Cropcho
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-23 00:00:00 -04:00
12
+ date: 2008-05-24 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15