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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d0928904addc15f172c1ca0045615ff80deef47
4
- data.tar.gz: 25fe2c483347fe26e163b24669e4f6d8e36410ec
3
+ metadata.gz: 4b2eea49ae061816cbe271e5190dec61dafd1ef1
4
+ data.tar.gz: 43361ddc40bd86cbace5005ef975af94bfd61b88
5
5
  SHA512:
6
- metadata.gz: e9460e299ab62557929c865860255e4e0e350297e55b2bf1bf1af90ae0eb3ca6f33c2cc90408590af69a8d86b1ff2e080419382df178d366cccc43435bb15889
7
- data.tar.gz: fb96b3a2bbc086c41ebe620a127c6922e09addff5e9c3dc0e081132852d506ec9f0557632c0a6e7d70ac626294bc80e0ee62cb8b81984a35d582e2c7831605e9
6
+ metadata.gz: 4aca5c1689f96555d7e641c471956c672b33acb20cfcf5c11c6f4b474d70c9b7aeb604b94f7947ad29186f694368a5cfefe416b10852d2baeff1776068147d88
7
+ data.tar.gz: a18596f0f64718da094d91b81ac06b7e0722cd990e0cafa49b29e4d73d19fd206880d92e9dfc089ffaff1ce6d2057bc225157c4bb139f4a8f7739bce851a6040
@@ -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 = pull value, key_handle if key_handle
47
- new_value = pull value, value_handle if value_handle
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
 
@@ -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: 1.1.0
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-01-11 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
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: :development
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
- description: |2
28
- For turning Arrays into Hashes, with keys computed from the Array
29
- contents. Or for rekeying Hashes.
30
-
31
- [ 1, 2, 3 ].rekey {|v| v}
32
- => { 1 => 1, 2 => 2, 3 => 3 }
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/d1hotpep/rekey
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.5.1
90
+ rubygems_version: 2.6.13
69
91
  signing_key:
70
92
  specification_version: 4
71
93
  summary: Rekey
@@ -1,3 +0,0 @@
1
- module Rekey
2
- VERSION = '1.1.0'
3
- end