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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c06dc75e5f426dc4ad79cfab2c4d1728c29fc7b
4
- data.tar.gz: 11c8dfcdb0b4a23aeecc091aa2e1caaa3dde37cd
3
+ metadata.gz: 69db1dc860cdcaf3662a7de6fed9b2311c4a2da6
4
+ data.tar.gz: 4ba311efc89556e778d5fd2ada3a5bb458b352f5
5
5
  SHA512:
6
- metadata.gz: 57943971842d5c0b76f0c14716d41040247e3de561e08f17b1634e08c3a648c250b75ec3a197a96a7b9564f06d6b05f2ae39633728ba593567bbb0ae18b382a9
7
- data.tar.gz: c1433c1310c53811469c1b301b32a8375bacd150dc9b36debaa66fd0933abeb96a6c47507c4b912edfc55aa5f9db91ae38a090bb834c7d6bf8a708ace72f71e1
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'
2
+ VERSION = '0.0.3'
3
3
 
4
4
  class << self
5
5
 
6
6
  def pluck v, handle
7
- if v.is_a? Array
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
@@ -16,6 +16,11 @@ class PluckItArrayTest < Minitest::Test
16
16
  [ 1, 4, 7 ],
17
17
  data.pluck(0)
18
18
  )
19
+
20
+ assert_equal(
21
+ [ 3, 6, 9 ],
22
+ data.pluck(:last)
23
+ )
19
24
  end
20
25
 
21
26
 
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluckit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper