pluckit 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pluckit.rb +6 -6
- data/test/test_array.rb +5 -0
- data/test/test_pluck.rb +14 -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: 69db1dc860cdcaf3662a7de6fed9b2311c4a2da6
|
4
|
+
data.tar.gz: 4ba311efc89556e778d5fd2ada3a5bb458b352f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a9f48b402f91dc30527fad8c501692cccff5880b13842cdbfacdead6cb197fe204267eea82bca4a5cee927b44b830875292ae77234b894c3c007cd2b603a40d
|
7
|
+
data.tar.gz: 7f1e9a08d78e3fad15c291301ababd9346b99c0a109a2284640dcf299e4b665b32d0dd07298082f20c613b997e25341030a3949007778bc3af2de7c5c5092360
|
data/lib/pluckit.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module PluckIt
|
2
|
-
VERSION = '0.0.
|
2
|
+
VERSION = '0.0.3'
|
3
3
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def pluck v, handle
|
7
|
-
if v.is_a?
|
7
|
+
if v.is_a? Hash
|
8
|
+
v[handle]
|
9
|
+
elsif ([Symbol, String].include? handle.class) and v.respond_to? handle
|
10
|
+
v.send handle
|
11
|
+
elsif v.is_a? Array
|
8
12
|
if handle.is_a? Regexp
|
9
13
|
v.grep handle
|
10
14
|
else
|
11
15
|
v[handle]
|
12
16
|
end
|
13
|
-
elsif v.is_a? Hash
|
14
|
-
v[handle]
|
15
|
-
elsif ([Symbol, String].include? handle.class) and v.respond_to? handle
|
16
|
-
v.send handle
|
17
17
|
else
|
18
18
|
raise ArgumentError.new "invalid handle: #{handle}, for value #{v}"
|
19
19
|
end
|
data/test/test_array.rb
CHANGED
data/test/test_pluck.rb
CHANGED
@@ -18,6 +18,16 @@ class PluckItTest < Minitest::Test
|
|
18
18
|
PluckIt.pluck(data, 1)
|
19
19
|
)
|
20
20
|
|
21
|
+
assert_equal(
|
22
|
+
3,
|
23
|
+
PluckIt.pluck(data, :last)
|
24
|
+
)
|
25
|
+
|
26
|
+
assert_equal(
|
27
|
+
3,
|
28
|
+
PluckIt.pluck(data, :count)
|
29
|
+
)
|
30
|
+
|
21
31
|
assert_equal(
|
22
32
|
[ 1, 2 ],
|
23
33
|
PluckIt.pluck(data, 0..1)
|
@@ -48,6 +58,10 @@ class PluckItTest < Minitest::Test
|
|
48
58
|
assert_nil(
|
49
59
|
PluckIt.pluck(data, :z)
|
50
60
|
)
|
61
|
+
|
62
|
+
assert_nil(
|
63
|
+
PluckIt.pluck(data, :count)
|
64
|
+
)
|
51
65
|
end
|
52
66
|
|
53
67
|
|