time_frame 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/time_frame/collection.rb +5 -0
- data/lib/time_frame/version.rb +1 -1
- data/spec/collection_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d91f181ec54007dec205fb4f579cfea5239ab3a5
|
4
|
+
data.tar.gz: 4f99fccea8014b5d159a1cbd7bc535a0825459fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db5553cf7505f6c75df2bb6d8b8f0024fdede6032333f70e69cef34052b3fdab50b81d0642dc974383f957437bb93d62c3f8ef993f31a5d91e3de26f15417c66
|
7
|
+
data.tar.gz: aa430375956dc1cce91092b52f40fa8fffba961d1d232af9aba962ca1c540657e1a971b39ffec09de838010afbc66185b6e005b8f3c0d93609b2d69d4b59ffc3
|
@@ -5,6 +5,7 @@ class TimeFrame
|
|
5
5
|
# access speed to intervals (or objects containing intervals) intersecting
|
6
6
|
# given time_frames or covering time elements
|
7
7
|
class Collection
|
8
|
+
include Enumerable
|
8
9
|
attr_reader :tree_nodes, :root
|
9
10
|
def initialize(item_list = [], sorted = false, &block)
|
10
11
|
@block = block ? block : ->(item) { item }
|
@@ -17,6 +18,10 @@ class TimeFrame
|
|
17
18
|
@root = @tree_nodes[(@tree_nodes.size - 1) / 2]
|
18
19
|
end
|
19
20
|
|
21
|
+
def each(&block)
|
22
|
+
tree_nodes.map { |node| node.item }.each(&block)
|
23
|
+
end
|
24
|
+
|
20
25
|
def all_covering(time)
|
21
26
|
result = []
|
22
27
|
add_covering(time, @root, result)
|
data/lib/time_frame/version.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -5,6 +5,15 @@ describe TimeFrame::Collection do
|
|
5
5
|
let(:time_frame) { TimeFrame.new(min: Time.utc(2014), duration: 20.days) }
|
6
6
|
let(:time) { Time.utc(2014) }
|
7
7
|
|
8
|
+
describe '#each' do
|
9
|
+
it 'has map implemented' do
|
10
|
+
time_frames = 20.times.map { |i| time_frame.shift_by((5 * i).days) }
|
11
|
+
objects = time_frames.map { |tf| OpenStruct.new(interval: tf) }
|
12
|
+
tree = TimeFrame::Collection.new(objects) { |o| o.interval }
|
13
|
+
expect(tree.map { |item| item.interval }).to eq time_frames
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
describe '#all_covering' do
|
9
18
|
context 'when a pure time_frame tree is given' do
|
10
19
|
it 'returns all covering time_frames' do
|