pluckit 0.0.3 → 0.1.0
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 +4 -4
- data/lib/pluckit.rb +16 -4
- data/test/test_array.rb +16 -0
- data/test/test_hash.rb +22 -0
- data/test/test_pluck.rb +15 -0
- data/test/test_set.rb +43 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f60041a9e7e6bf150d5f7a8d9cdaa72b795650b
|
4
|
+
data.tar.gz: fd72fe2ed30100f8e5a07d1fe531d41153b91bb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d61d2afa5f0b1308cf2c47c88a317b16174f81cb54cdd87e2104290c85789ad062c0447a77f1c2220389e82aa1df026396534caa3879cf702f5dcdce3a8d42f9
|
7
|
+
data.tar.gz: 78982ef586f5c3b8b3b202715c25a73d09d8be9c6df6fe9ee47cc71778941ab49d18ee7c0922453c036f492995e0ae3b5909bff4bd7d7b1c09beb3843d6e6c31
|
data/lib/pluckit.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module PluckIt
|
2
|
-
VERSION = '0.0
|
2
|
+
VERSION = '0.1.0'
|
3
3
|
|
4
4
|
class << self
|
5
5
|
|
@@ -25,14 +25,26 @@ end
|
|
25
25
|
|
26
26
|
class Array
|
27
27
|
def pluck(handle)
|
28
|
-
|
28
|
+
each_with_object(clone.clear) do |val, res|
|
29
|
+
res << PluckIt.pluck(val, handle)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
|
33
35
|
class Hash
|
34
36
|
def pluck(handle)
|
35
|
-
|
36
|
-
|
37
|
+
each_with_object(clone.clear) do |(key, val), res|
|
38
|
+
res[key] = PluckIt.pluck(val, handle)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
class Set
|
45
|
+
def pluck(handle)
|
46
|
+
each_with_object(clone.clear) do |val, res|
|
47
|
+
res.add PluckIt.pluck(val, handle)
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|
data/test/test_array.rb
CHANGED
@@ -81,4 +81,20 @@ class PluckItArrayTest < Minitest::Test
|
|
81
81
|
end
|
82
82
|
|
83
83
|
|
84
|
+
class MyArray < Array; end
|
85
|
+
def test_clone
|
86
|
+
data = MyArray.new [ 1, 2, 3 ]
|
87
|
+
|
88
|
+
assert_equal(
|
89
|
+
[ 1, 2, 3 ],
|
90
|
+
data.pluck(:itself)
|
91
|
+
)
|
92
|
+
|
93
|
+
assert_equal(
|
94
|
+
self.class.const_get(:MyArray),
|
95
|
+
data.pluck(:itself).class
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
|
84
100
|
end
|
data/test/test_hash.rb
CHANGED
@@ -55,4 +55,26 @@ class PluckItHashTest < Minitest::Test
|
|
55
55
|
end
|
56
56
|
|
57
57
|
|
58
|
+
class MyHash < Hash; end
|
59
|
+
def test_clone
|
60
|
+
data = MyHash.new 'abc'
|
61
|
+
data.update a: 1
|
62
|
+
|
63
|
+
assert_equal(
|
64
|
+
{ a: 1 },
|
65
|
+
data.pluck(:itself)
|
66
|
+
)
|
67
|
+
|
68
|
+
assert_equal(
|
69
|
+
'abc',
|
70
|
+
data.pluck(:itself)[:missing]
|
71
|
+
)
|
72
|
+
|
73
|
+
assert_equal(
|
74
|
+
self.class.const_get(:MyHash),
|
75
|
+
data.pluck(:itself).class
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
58
80
|
end
|
data/test/test_pluck.rb
CHANGED
data/test/test_set.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'pluckit'
|
3
|
+
|
4
|
+
|
5
|
+
class PluckItSetTest < Minitest::Test
|
6
|
+
|
7
|
+
|
8
|
+
def test_basic
|
9
|
+
data = Set.new [
|
10
|
+
[ 1, 2, 3 ],
|
11
|
+
[ 4, 5, 6 ],
|
12
|
+
[ 7, 8, 9 ],
|
13
|
+
]
|
14
|
+
|
15
|
+
assert_equal(
|
16
|
+
Set.new([ 1, 4, 7 ]),
|
17
|
+
data.pluck(0)
|
18
|
+
)
|
19
|
+
|
20
|
+
assert_equal(
|
21
|
+
Set.new([ 3, 6, 9 ]),
|
22
|
+
data.pluck(:last)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
class MySet < Set; end
|
28
|
+
def test_clone
|
29
|
+
data = MySet.new [ 1, 2, 3 ]
|
30
|
+
|
31
|
+
assert_equal(
|
32
|
+
Set.new([ 1, 2, 3 ]),
|
33
|
+
data.pluck(:itself)
|
34
|
+
)
|
35
|
+
|
36
|
+
assert_equal(
|
37
|
+
self.class.const_get(:MySet),
|
38
|
+
data.pluck(:itself).class
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluckit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- test/test_array.rb
|
49
49
|
- test/test_hash.rb
|
50
50
|
- test/test_pluck.rb
|
51
|
+
- test/test_set.rb
|
51
52
|
homepage: https://github.com/dpep/pluckit
|
52
53
|
licenses:
|
53
54
|
- MIT
|
@@ -76,3 +77,4 @@ test_files:
|
|
76
77
|
- test/test_array.rb
|
77
78
|
- test/test_hash.rb
|
78
79
|
- test/test_pluck.rb
|
80
|
+
- test/test_set.rb
|