hash-pipe 0.1.1 → 0.2.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: 5a8f375ae022cfd53366c69371f5b15bb2d661c9
4
- data.tar.gz: 9f7633a90fbdf61bab4a52d6238d556e46aa7d28
3
+ metadata.gz: 8317453dcbfcc0f2e4f639c777b81957a37844c0
4
+ data.tar.gz: 5979979f40acc682dd5c29146f338c0223ebf0da
5
5
  SHA512:
6
- metadata.gz: be548be7aca55c7692a2b6a4841eb58444f13d46107cc97ddf6dff86a40a563ffef1ab839989830576bbd6a5bdd8a228a9aedf388d679be0b4e397688aa42b5a
7
- data.tar.gz: ffaffb69d2f71db76825d41513c73e9d699438e2361a72d67a96cd0f6f69f4e86fe0ba85f711a4ae5de32eb6397fb31c99f34b80aa6b59a29e4e69f44c2494f4
6
+ metadata.gz: 42fe12c24ade00fdb0203e93d74294cf92dc2a981c56ddbe8e36f5f08d1113135af8adff85d9ee6a35d9c33c840a329de4fcceeccb5691f3972d678fb561c5a4
7
+ data.tar.gz: b6f6d992e1fd9f5a2423b76777ec9f9e3be8b5411f6e2c72e2ba1ee1dd94e7c67fdee3d7087593364f588a4d492d6b006c5dd36fd518c4c45ef8255d79318012
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hash-pipe (0.1.1)
4
+ hash-pipe (0.2.0)
5
5
  activesupport (~> 4.1)
6
6
 
7
7
  GEM
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "hash-pipe"
5
- s.version = "0.1.1"
5
+ s.version = "0.2.0"
6
6
  s.authors = ["Damien Timewell"]
7
7
  s.email = ["mail@damientimewell.com"]
8
8
  s.licenses = ['MIT']
@@ -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, method) }
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
- [ key.to_s.send(method), convert_keys(value, method) ]
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.1.1
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-01-26 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport