collection_of 1.0.3 → 1.0.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.
- checksums.yaml +8 -8
- data/lib/collection_of/collection.rb +5 -0
- data/lib/collection_of/version.rb +1 -1
- data/spec/collection_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjcwOTY5N2JlNzAyYjc5ZDU2M2EwMTc1OWFmOGZiNTYzNGU3OGY2Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGRjOWE1ZmNmNjI4ZDc1ZTU0ODMwMjA1ZGNjZTZlNjBlYTVkMjg1OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWI2ZmY5NTVmZWI5YjYwYTM5YTcwNzg3YmUwNjA0ZDg2NjE2ODgwY2M4MWI0
|
10
|
+
YzQzN2YzNTdmYTkzYmZiN2Y3MjI5NGY3Mjg5M2UxOWU3ODJlOGZjYTU1Y2Yw
|
11
|
+
MDZmNDFjOGIyMTE5MTU2Y2VkNjhkN2VjM2ZlZjEwM2YwZGM3Yjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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)
|
data/spec/collection_spec.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
type: :runtime
|