acts_as_flux_capacitor 0.5.3 → 0.5.4
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
@@ -290,7 +290,7 @@ private
|
|
290
290
|
module CompareEvents
|
291
291
|
def overlaps_with?(other_event)
|
292
292
|
#this method possesses the associative property.
|
293
|
-
self.to_range.
|
293
|
+
self.to_range.overlaps?(other_event.to_range)
|
294
294
|
end
|
295
295
|
|
296
296
|
def overlap_with(other_event)
|
@@ -1,22 +1,19 @@
|
|
1
1
|
class Range
|
2
2
|
|
3
|
-
# the
|
3
|
+
# the overlaps?(range) method comes from ActiveSupport::CoreExtensions::Range
|
4
|
+
# thanks to Nick Ang for suggesting its use.
|
5
|
+
# most of its tests were written by Jack Christensen of
|
4
6
|
# http://www.jackchristensen.com/article/2/detecting-overlapping-ranges
|
5
7
|
|
6
8
|
# Returns true if ranges overlap, false otherwise
|
7
|
-
def
|
8
|
-
|
9
|
-
last < other_range.first ||
|
10
|
-
(last == other_range.first && exclude_end?) ||
|
11
|
-
other_range.last < first ||
|
12
|
-
(other_range.last == first && other_range.exclude_end?)
|
13
|
-
)
|
9
|
+
def overlaps? other
|
10
|
+
include?(other.first) || other.include?(first)
|
14
11
|
end
|
15
12
|
|
16
13
|
# all of this added by jim cropcho:
|
17
14
|
|
18
15
|
def overlap(other_range)
|
19
|
-
return 0 unless self.
|
16
|
+
return 0 unless self.overlaps?(other_range)
|
20
17
|
|
21
18
|
overlap_range = greater_of(self.first,other_range.first)..smaller_of(self.last,other_range.last)
|
22
19
|
# puts "overlap range: #{overlap_range}"
|
@@ -55,4 +52,4 @@ private
|
|
55
52
|
def smaller_of(num1,num2)
|
56
53
|
num1 < num2 ? num1 : num2
|
57
54
|
end
|
58
|
-
end
|
55
|
+
end
|
@@ -188,3 +188,56 @@ describe "The TimePeriod modification helpers" do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
end
|
191
|
+
|
192
|
+
describe "The Range overlap helpers" do
|
193
|
+
|
194
|
+
it "should determine if two ranges do not overlap" do
|
195
|
+
# 1-------10
|
196
|
+
# 20-------30
|
197
|
+
(1..10).overlaps?(20..30).should be_false
|
198
|
+
(1..10).overlap(20..30).should eql(0)
|
199
|
+
|
200
|
+
# 20-------30
|
201
|
+
# 1-------10
|
202
|
+
(20..30).overlaps?(1..10).should be_false
|
203
|
+
(20..30).overlap(1..10).should eql(0)
|
204
|
+
|
205
|
+
# 1-------10
|
206
|
+
# 10-------20
|
207
|
+
(1...10).overlaps?(10..20).should be_false
|
208
|
+
(1...10).overlap(10..20).should eql(0)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should determine if two ranges do overlap" do
|
212
|
+
tolerance = 0.01
|
213
|
+
|
214
|
+
# 1-------10
|
215
|
+
# 10-------20
|
216
|
+
(1..10).overlaps?(10..20).should be_true
|
217
|
+
(1..10).overlap(10..20).size.should be_close(1.0,tolerance)
|
218
|
+
|
219
|
+
# 1-----------15
|
220
|
+
# 10-------20
|
221
|
+
(1..15).overlaps?(10..20).should be_true
|
222
|
+
(1..15).overlap(10..20).size.should be_close(6.0,tolerance)
|
223
|
+
|
224
|
+
# 5--------15
|
225
|
+
# 1-------10
|
226
|
+
(5..15).overlaps?(1..10).should be_true
|
227
|
+
(5..15).overlap(1..10).size.should be_close(6.0,tolerance)
|
228
|
+
|
229
|
+
# 10--------20
|
230
|
+
# 1-------10
|
231
|
+
(10..20).overlaps?(1..10).should be_true
|
232
|
+
(10..20).overlap(1..10).size.should be_close(1.0,tolerance)
|
233
|
+
|
234
|
+
# 1-----------------20
|
235
|
+
# 5---------15
|
236
|
+
(1..20).overlaps?(5..15).should be_true
|
237
|
+
(1..20).overlap(5..15).size.should be_close(11.0,tolerance)
|
238
|
+
|
239
|
+
(5..15).overlaps?(1..20).should be_true
|
240
|
+
(5..15).overlap(1..20).size.should be_close(11.0,tolerance)
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
data/spec/report.html
CHANGED
@@ -179,95 +179,104 @@ 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('3.
|
182
|
+
<script type="text/javascript">moveProgressBar('3.1');</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('6.
|
184
|
+
<script type="text/javascript">moveProgressBar('6.2');</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('
|
186
|
+
<script type="text/javascript">moveProgressBar('9.3');</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('
|
188
|
+
<script type="text/javascript">moveProgressBar('12.5');</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('
|
190
|
+
<script type="text/javascript">moveProgressBar('15.6');</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('
|
192
|
+
<script type="text/javascript">moveProgressBar('18.7');</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('
|
194
|
+
<script type="text/javascript">moveProgressBar('21.8');</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('
|
196
|
+
<script type="text/javascript">moveProgressBar('25.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 < ActiveRecord::Base</dt>
|
203
|
-
<script type="text/javascript">moveProgressBar('
|
203
|
+
<script type="text/javascript">moveProgressBar('28.1');</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('
|
205
|
+
<script type="text/javascript">moveProgressBar('31.2');</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('
|
207
|
+
<script type="text/javascript">moveProgressBar('34.3');</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('
|
209
|
+
<script type="text/javascript">moveProgressBar('37.5');</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('
|
216
|
+
<script type="text/javascript">moveProgressBar('40.6');</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('
|
218
|
+
<script type="text/javascript">moveProgressBar('43.7');</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('
|
220
|
+
<script type="text/javascript">moveProgressBar('46.8');</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('
|
222
|
+
<script type="text/javascript">moveProgressBar('50.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('
|
224
|
+
<script type="text/javascript">moveProgressBar('53.1');</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('
|
231
|
+
<script type="text/javascript">moveProgressBar('56.2');</script>
|
232
232
|
<dd class="spec passed"><span class="passed_spec_name">should calculate the time between time_periods</span></dd>
|
233
|
-
<script type="text/javascript">moveProgressBar('
|
233
|
+
<script type="text/javascript">moveProgressBar('59.3');</script>
|
234
234
|
<dd class="spec passed"><span class="passed_spec_name">should determine whether two time_periods overlap</span></dd>
|
235
|
-
<script type="text/javascript">moveProgressBar('
|
235
|
+
<script type="text/javascript">moveProgressBar('62.5');</script>
|
236
236
|
<dd class="spec passed"><span class="passed_spec_name">should determine the length of time by which two time_periods overlap</span></dd>
|
237
|
-
<script type="text/javascript">moveProgressBar('
|
237
|
+
<script type="text/javascript">moveProgressBar('65.6');</script>
|
238
238
|
<dd class="spec passed"><span class="passed_spec_name">should determine if two time_periods are back-to-back</span></dd>
|
239
|
-
<script type="text/javascript">moveProgressBar('
|
239
|
+
<script type="text/javascript">moveProgressBar('68.7');</script>
|
240
240
|
<dd class="spec passed"><span class="passed_spec_name">should determine if a time_period is between two other time_periods</span></dd>
|
241
241
|
</dl>
|
242
242
|
</div>
|
243
243
|
<div class="example_group">
|
244
244
|
<dl>
|
245
245
|
<dt id="example_group_5">The TimePeriod status helpers</dt>
|
246
|
-
<script type="text/javascript">moveProgressBar('
|
246
|
+
<script type="text/javascript">moveProgressBar('71.8');</script>
|
247
247
|
<dd class="spec passed"><span class="passed_spec_name">should determine if a time_period has started</span></dd>
|
248
|
-
<script type="text/javascript">moveProgressBar('
|
248
|
+
<script type="text/javascript">moveProgressBar('75.0');</script>
|
249
249
|
<dd class="spec passed"><span class="passed_spec_name">should determine how much time has elapsed since an event started</span></dd>
|
250
|
-
<script type="text/javascript">moveProgressBar('
|
250
|
+
<script type="text/javascript">moveProgressBar('78.1');</script>
|
251
251
|
<dd class="spec passed"><span class="passed_spec_name">should determine what percentage of time has elapsed since an event started</span></dd>
|
252
|
-
<script type="text/javascript">moveProgressBar('
|
252
|
+
<script type="text/javascript">moveProgressBar('81.2');</script>
|
253
253
|
<dd class="spec passed"><span class="passed_spec_name">should determine how much time is remaining until an event ends</span></dd>
|
254
|
-
<script type="text/javascript">moveProgressBar('
|
254
|
+
<script type="text/javascript">moveProgressBar('84.3');</script>
|
255
255
|
<dd class="spec passed"><span class="passed_spec_name">should determine what percentage of time is remaining until an event ends</span></dd>
|
256
|
-
<script type="text/javascript">moveProgressBar('
|
256
|
+
<script type="text/javascript">moveProgressBar('87.5');</script>
|
257
257
|
<dd class="spec passed"><span class="passed_spec_name">should determine if a time_period has ended</span></dd>
|
258
|
-
<script type="text/javascript">moveProgressBar('
|
258
|
+
<script type="text/javascript">moveProgressBar('90.6');</script>
|
259
259
|
<dd class="spec passed"><span class="passed_spec_name">should determine the duration of a time_period</span></dd>
|
260
260
|
</dl>
|
261
261
|
</div>
|
262
262
|
<div class="example_group">
|
263
263
|
<dl>
|
264
264
|
<dt id="example_group_6">The TimePeriod modification helpers</dt>
|
265
|
-
<script type="text/javascript">moveProgressBar('
|
265
|
+
<script type="text/javascript">moveProgressBar('93.7');</script>
|
266
266
|
<dd class="spec passed"><span class="passed_spec_name">should shift a time_period into the past or future</span></dd>
|
267
267
|
</dl>
|
268
268
|
</div>
|
269
|
-
<
|
270
|
-
<
|
269
|
+
<div class="example_group">
|
270
|
+
<dl>
|
271
|
+
<dt id="example_group_7">The Range overlap helpers</dt>
|
272
|
+
<script type="text/javascript">moveProgressBar('96.8');</script>
|
273
|
+
<dd class="spec passed"><span class="passed_spec_name">should determine if two ranges do not overlap</span></dd>
|
274
|
+
<script type="text/javascript">moveProgressBar('100.0');</script>
|
275
|
+
<dd class="spec passed"><span class="passed_spec_name">should determine if two ranges do overlap</span></dd>
|
276
|
+
</dl>
|
277
|
+
</div>
|
278
|
+
<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>0.321167 seconds</strong>";</script>
|
279
|
+
<script type="text/javascript">document.getElementById('totals').innerHTML = "32 examples, 0 failures";</script>
|
271
280
|
</div>
|
272
281
|
</div>
|
273
282
|
</body>
|
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.5.
|
4
|
+
version: 0.5.4
|
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-
|
12
|
+
date: 2008-05-22 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|