collection_of 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTUzMGY4NTExZjJkOGU1NGUwZmFhNTU5NGY3NTA0YjZjZDQxOTNkYQ==
4
+ NjcwOTY5N2JlNzAyYjc5ZDU2M2EwMTc1OWFmOGZiNTYzNGU3OGY2Mg==
5
5
  data.tar.gz: !binary |-
6
- N2UzZjFhMTA5M2ZiYTFhOTUwMWI4ZjA5ODRkN2E2NTAxOTI5Zjc5MQ==
6
+ MGRjOWE1ZmNmNjI4ZDc1ZTU0ODMwMjA1ZGNjZTZlNjBlYTVkMjg1OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjRlZGY4MTllODBiZDgyY2I5ODhiNDcxMjI1ZDFjZDE5MTAyZTJlNWQ5NGQx
10
- MjcyNzAwNmU2NzU3NjNjMjYxMzg2NmQyNTNhMThmNmM4MmZhYzRkZWYyZjlm
11
- ZDE0Yjc1MDcxZTcyNjdkZTA3MDQzZjgwZDY4MjZlZDJiNTA4MmI=
9
+ ZWI2ZmY5NTVmZWI5YjYwYTM5YTcwNzg3YmUwNjA0ZDg2NjE2ODgwY2M4MWI0
10
+ YzQzN2YzNTdmYTkzYmZiN2Y3MjI5NGY3Mjg5M2UxOWU3ODJlOGZjYTU1Y2Yw
11
+ MDZmNDFjOGIyMTE5MTU2Y2VkNjhkN2VjM2ZlZjEwM2YwZGM3Yjk=
12
12
  data.tar.gz: !binary |-
13
- MTQ1NDRkMWIyZWVhNmQ1YTZkNjQyMTU3NDM5NDI4MDc5YTMwNWU2NzU1ZDUw
14
- MjIzNWNlZDllNTU2NjNhNGE5NTgxNTBjMjM2YzM2NjY5NmFlOGNkNmEwZjI3
15
- MDM4MGExOGQwZWE3Yzg3NTk2MzAwMjI1MGM0MDY0YTAxOTdhZGI=
13
+ NzYzYTdkZmJkODE1MGU2MTFiZTU3ZThhNWM2Mjk2YjEzNzQyMTc2ODc4ODg1
14
+ OTI0YjdhYmJmZjhmZjM0MGZlMzI1Nzg2ZjQ5NmE2MGZmMDEzMDczNjFhMWJj
15
+ NjFhNWIxZmI3MzcxY2NlNmE3MDEzODIzMzhmY2I4NjVkNTBmMmQ=
@@ -71,6 +71,11 @@ class Collection
71
71
  self.class.new(klass, reject{ |i| items.include?(i.name.to_sym) })
72
72
  end
73
73
 
74
+ def slice(*items)
75
+ items.map!(&:to_sym)
76
+ self.class.new(klass, select{ |i| items.include?(i.name.to_sym) })
77
+ end
78
+
74
79
  def ==(other)
75
80
  return other == @collection if other.is_a?(self.class)
76
81
  return @collection == other if other.is_a?(Array)
@@ -1,3 +1,3 @@
1
1
  module CollectionOf
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -201,6 +201,32 @@ describe Collection do
201
201
  end
202
202
  end
203
203
 
204
+ describe "#slice" do
205
+ let(:c) { described_class[Widget] }
206
+ let(:w1) { Widget.new(:one) }
207
+ let(:w2) { Widget.new(:two) }
208
+
209
+ before { c << w1 << w2 }
210
+
211
+ context "when an include item is specified" do
212
+ subject { c.slice(:one) }
213
+ it { should be_a described_class }
214
+ it { should == [w1] }
215
+ end
216
+
217
+ context "when all included items are specified" do
218
+ subject { c.slice(:one, :two) }
219
+ it { should be_a described_class }
220
+ it { should == [w1, w2] }
221
+ end
222
+
223
+ context "when no included items are specified" do
224
+ subject { c.slice(:three) }
225
+ it { should be_a described_class }
226
+ it { should be_empty }
227
+ end
228
+ end
229
+
204
230
  describe "#==" do
205
231
  let(:w1) { Widget.new(:one) }
206
232
  let(:w2) { Widget.new(:two) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collection_of
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-20 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  type: :runtime