hash-pipe 0.1.1 → 0.2.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/Gemfile.lock +1 -1
- data/hash-pipe.gemspec +1 -1
- data/lib/hash_pipe/key_conversion.rb +8 -2
- data/spec/hash-pipe/key_conversion_spec.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8317453dcbfcc0f2e4f639c777b81957a37844c0
|
4
|
+
data.tar.gz: 5979979f40acc682dd5c29146f338c0223ebf0da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42fe12c24ade00fdb0203e93d74294cf92dc2a981c56ddbe8e36f5f08d1113135af8adff85d9ee6a35d9c33c840a329de4fcceeccb5691f3972d678fb561c5a4
|
7
|
+
data.tar.gz: b6f6d992e1fd9f5a2423b76777ec9f9e3be8b5411f6e2c72e2ba1ee1dd94e7c67fdee3d7087593364f588a4d492d6b006c5dd36fd518c4c45ef8255d79318012
|
data/Gemfile.lock
CHANGED
data/hash-pipe.gemspec
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
Hash.class_eval do
|
2
2
|
|
3
3
|
def self.convert_keys(hash, method = :underscore)
|
4
|
+
if method.is_a? Proc
|
5
|
+
converter = method
|
6
|
+
else
|
7
|
+
converter = -> (str) { str.to_s.send method }
|
8
|
+
end
|
9
|
+
|
4
10
|
if hash.is_a?(Array)
|
5
|
-
hash.collect {|h| convert_keys(h,
|
11
|
+
hash.collect {|h| convert_keys(h, converter) }
|
6
12
|
elsif hash.is_a?(Hash)
|
7
13
|
hash_array = hash.collect do |key,value|
|
8
|
-
[
|
14
|
+
[ converter.call(key), convert_keys(value, converter) ]
|
9
15
|
end
|
10
16
|
|
11
17
|
Hash[hash_array]
|
@@ -35,4 +35,9 @@ describe 'key_conversion' do
|
|
35
35
|
Hash.convert_keys("HELLO WORLD").should eq "HELLO WORLD"
|
36
36
|
end
|
37
37
|
|
38
|
+
it 'should support lambdas for conversion methods' do
|
39
|
+
converter = -> (str) { str.sub "hello", "goodbye" }
|
40
|
+
{ 'hello' => 'world' }.convert_keys(converter).should eq 'goodbye' => 'world'
|
41
|
+
end
|
42
|
+
|
38
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash-pipe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|