time_frame 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/time_frame/time_frame_uniter.rb +6 -5
- data/lib/time_frame/version.rb +1 -1
- data/spec/time_frame_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 956de9d650db7ad301e9b4b903cd330b0630d866
|
4
|
+
data.tar.gz: 32c2a3d2249e19ee5ac6ad6335d15952c9278816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1fe690605128abd552bb893a6e4176343c453738f92efa9c935b8e7876d89ed358ca8ecf155f0af8ddd2d1e6b23ec712a5a778b0fd3c3700645eeab2cf8845
|
7
|
+
data.tar.gz: 92c452c7bcd63b6651d545a3d41ea15b11e48d575b02899a54ebe0726d0668fee25d54a0ecb6c2e79fbbd6f06b277fd26818ee4eff896f521f573c2d048308b0
|
data/Gemfile
CHANGED
@@ -10,12 +10,13 @@ class TimeFrame
|
|
10
10
|
|
11
11
|
def unite
|
12
12
|
frames = @sorted ? @time_frames : @time_frames.sort_by(&:min)
|
13
|
-
frames.each_with_object([]) do |
|
14
|
-
|
15
|
-
if
|
16
|
-
|
13
|
+
frames.each_with_object([]) do |next_time_frame, result|
|
14
|
+
last_time_frame = result.last
|
15
|
+
if last_time_frame && last_time_frame.cover?(next_time_frame.min)
|
16
|
+
max = [last_time_frame.max, next_time_frame.max].max
|
17
|
+
result[-1] = TimeFrame.new(min: last_time_frame.min, max: max)
|
17
18
|
else
|
18
|
-
result <<
|
19
|
+
result << next_time_frame
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
data/lib/time_frame/version.rb
CHANGED
data/spec/time_frame_spec.rb
CHANGED
@@ -395,6 +395,15 @@ describe TimeFrame do
|
|
395
395
|
subject { TimeFrame.union([time_frame1, time_frame2]) }
|
396
396
|
it { should eq expected }
|
397
397
|
end
|
398
|
+
context 'that are overlapping and first contains the second' do
|
399
|
+
let(:time_frame1) { TimeFrame.new(min: time, duration: 3.hours) }
|
400
|
+
let(:time_frame2) do
|
401
|
+
TimeFrame.new(min: time + 1.hour, duration: 1.hour)
|
402
|
+
end
|
403
|
+
let(:expected) { [time_frame1] }
|
404
|
+
subject { TimeFrame.union([time_frame1, time_frame2]) }
|
405
|
+
it { should eq expected }
|
406
|
+
end
|
398
407
|
context 'that are disjoint' do
|
399
408
|
let(:time_frame1) { TimeFrame.new(min: time, duration: 2.hours) }
|
400
409
|
let(:time_frame2) { time_frame1.shift_by(3.hours) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_frame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Derichs
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-07-
|
13
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|