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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef554cd54e51a1fc22a6c16b6cf1bac7b43b19d8
4
- data.tar.gz: 319e9ef2ced0c9ec7f4fe221cc22c4e48743a2a6
3
+ metadata.gz: d91f181ec54007dec205fb4f579cfea5239ab3a5
4
+ data.tar.gz: 4f99fccea8014b5d159a1cbd7bc535a0825459fe
5
5
  SHA512:
6
- metadata.gz: ac152a3d12403ee212d374f1282f2ec3d63cc39d223d6e292680e8ea6e45fbcb55b1b465319fa0d8bfb448d6b33a444e53d74c4341aacfee8fe2f1a737bd9333
7
- data.tar.gz: a5a439ab393e88bcef9195d632c8b774e7c88f538e9bce1efea20ace56ba76c182f5cf3d8deb43cf0e77f36d50e1b5357682000418321872fdc2fed072b8869b
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)
@@ -1,5 +1,5 @@
1
1
  # Encoding: utf-8
2
2
  # gem version
3
3
  class TimeFrame
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -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
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Derichs