rekey 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rekey.rb +8 -23
- data/test/test_array_handlers.rb +0 -30
- metadata +37 -15
- data/lib/rekey/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b2eea49ae061816cbe271e5190dec61dafd1ef1
|
4
|
+
data.tar.gz: 43361ddc40bd86cbace5005ef975af94bfd61b88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aca5c1689f96555d7e641c471956c672b33acb20cfcf5c11c6f4b474d70c9b7aeb604b94f7947ad29186f694368a5cfefe416b10852d2baeff1776068147d88
|
7
|
+
data.tar.gz: a18596f0f64718da094d91b81ac06b7e0722cd990e0cafa49b29e4d73d19fd206880d92e9dfc089ffaff1ce6d2057bc225157c4bb139f4a8f7739bce851a6040
|
data/lib/rekey.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
require 'pluckit'
|
2
|
+
|
3
|
+
|
1
4
|
module Rekey
|
5
|
+
VERSION = '2.0.0'
|
6
|
+
|
2
7
|
class << self
|
3
8
|
|
4
9
|
def rekey(enumerable, key_handle = nil, value_handle = nil, &block)
|
@@ -34,6 +39,7 @@ module Rekey
|
|
34
39
|
# standard block
|
35
40
|
new_key = block.call value
|
36
41
|
else
|
42
|
+
# block that wants both key and value
|
37
43
|
data = block.call key, value
|
38
44
|
if data.is_a? Array
|
39
45
|
new_key, new_value = data
|
@@ -43,8 +49,8 @@ module Rekey
|
|
43
49
|
end
|
44
50
|
end
|
45
51
|
else
|
46
|
-
new_key =
|
47
|
-
new_value =
|
52
|
+
new_key = PluckIt.pluck value, key_handle if key_handle
|
53
|
+
new_value = PluckIt.pluck value, value_handle if value_handle
|
48
54
|
end
|
49
55
|
|
50
56
|
# collect results
|
@@ -110,27 +116,6 @@ module Rekey
|
|
110
116
|
end
|
111
117
|
end
|
112
118
|
|
113
|
-
|
114
|
-
def pull v, handle
|
115
|
-
if ([Symbol, String].include? handle.class) and v.respond_to? handle
|
116
|
-
if v.method(handle).arity <= 0
|
117
|
-
v.send handle
|
118
|
-
else
|
119
|
-
v.send handle, v
|
120
|
-
end
|
121
|
-
elsif v.is_a? Array
|
122
|
-
if handle.is_a? Regexp
|
123
|
-
v.grep handle
|
124
|
-
else
|
125
|
-
v[handle]
|
126
|
-
end
|
127
|
-
elsif v.is_a? Hash
|
128
|
-
v[handle]
|
129
|
-
else
|
130
|
-
raise ArgumentError.new "invalid handle: #{handle}, for value #{v}"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
119
|
end
|
135
120
|
end
|
136
121
|
|
data/test/test_array_handlers.rb
CHANGED
@@ -124,36 +124,6 @@ class RekeyArrayHandlersTest < Minitest::Test
|
|
124
124
|
)
|
125
125
|
end
|
126
126
|
|
127
|
-
def test_array_hash
|
128
|
-
data = [
|
129
|
-
{ a: 1 },
|
130
|
-
{ b: 2 },
|
131
|
-
{ c: 3 },
|
132
|
-
]
|
133
|
-
|
134
|
-
assert_equal(
|
135
|
-
[ [:a], [:b], [:c] ],
|
136
|
-
data.rekey(nil, :keys)
|
137
|
-
)
|
138
|
-
|
139
|
-
assert_equal(
|
140
|
-
[ :a, :b, :c ],
|
141
|
-
data.rekey(nil, :keys).rekey(nil, :first)
|
142
|
-
)
|
143
|
-
|
144
|
-
assert_equal({
|
145
|
-
{ a: 1 }.hash => data.first,
|
146
|
-
},
|
147
|
-
data.take(1).rekey(:hash)
|
148
|
-
)
|
149
|
-
|
150
|
-
assert_equal({
|
151
|
-
{ a: 1 }.hash => [:a, 1],
|
152
|
-
},
|
153
|
-
data.take(1).rekey(:hash, :first)
|
154
|
-
)
|
155
|
-
end
|
156
|
-
|
157
127
|
|
158
128
|
def test_hash_indices
|
159
129
|
data = [
|
metadata
CHANGED
@@ -1,42 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rekey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: pluckit
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10'
|
55
|
+
description: Reformat Enumerables into Hashes, using derived keys / values
|
33
56
|
email:
|
34
57
|
executables: []
|
35
58
|
extensions: []
|
36
59
|
extra_rdoc_files: []
|
37
60
|
files:
|
38
61
|
- lib/rekey.rb
|
39
|
-
- lib/rekey/version.rb
|
40
62
|
- test/test_array_block.rb
|
41
63
|
- test/test_array_handlers.rb
|
42
64
|
- test/test_empty_input.rb
|
@@ -45,7 +67,7 @@ files:
|
|
45
67
|
- test/test_invalid_input.rb
|
46
68
|
- test/test_range.rb
|
47
69
|
- test/test_regexp.rb
|
48
|
-
homepage: https://github.com/
|
70
|
+
homepage: https://github.com/dpep/rekey
|
49
71
|
licenses:
|
50
72
|
- MIT
|
51
73
|
metadata: {}
|
@@ -65,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
87
|
version: '0'
|
66
88
|
requirements: []
|
67
89
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.6.13
|
69
91
|
signing_key:
|
70
92
|
specification_version: 4
|
71
93
|
summary: Rekey
|
data/lib/rekey/version.rb
DELETED