hash_kit 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hash_kit/helper.rb +24 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cda8f2f6c623b14143702e178971f8e32384fff
4
- data.tar.gz: 31d76b84f42340ba5a626c907c53c83b24784ad2
3
+ metadata.gz: 1f90e18ad4471abb39b5b80f89214a258e3621c7
4
+ data.tar.gz: 9e1abd5eb88d5f1be74db2156e90514da383eda5
5
5
  SHA512:
6
- metadata.gz: 8aa32033e917eba91320285f75f9dce9d2004e5a7ab1d46caa0f475b2b81856b8ec305e7c1c39c05aa8c076c45a46c540d19ec2afefe41414b4c268290501452
7
- data.tar.gz: 130846e400f1f182492bf4a52bb2eba6dec664711948be14530427f7658999c78b21a8abcf99e43667fb994efc45f374608752484ef8e708cfa075eb17224102
6
+ metadata.gz: 44c314d95ef6201e74c315af2149293f119e335fb848c7d845ec95552863a58c7404bda5c71601ea3423ac5521b3c3714ed6e87a41ae0b3cdcd1aea1c134f868
7
+ data.tar.gz: 786a798cc07e83965e48af4f828b82aebee98aeb99464cefb23290db70541c94c58f933f343a9089dde974c8d45f6a28931175a9ac6f602fae35ba169234a337
@@ -3,6 +3,10 @@ module HashKit
3
3
 
4
4
  #This method is called to make a hash allow indifferent access (it will accept both strings & symbols for a valid key).
5
5
  def indifferent!(hash)
6
+ unless hash.is_a?(Hash)
7
+ return
8
+ end
9
+
6
10
  #set the default proc to allow the key to be either string or symbol if a matching key is found.
7
11
  hash.default_proc = proc do |h, k|
8
12
  if h.key?(k.to_s)
@@ -16,14 +20,32 @@ module HashKit
16
20
 
17
21
  #recursively process any child hashes
18
22
  hash.each do |key,value|
19
- if hash[key] != nil && hash[key].is_a?(Hash)
20
- indifferent(hash[key])
23
+ if hash[key] != nil
24
+ if hash[key].is_a?(Hash)
25
+ indifferent!(hash[key])
26
+ elsif hash[key].is_a?(Array)
27
+ indifferent_array!(hash[key])
28
+ end
21
29
  end
22
30
  end
23
31
 
24
32
  hash
25
33
  end
26
34
 
35
+ def indifferent_array!(array)
36
+ unless array.is_a?(Array)
37
+ return
38
+ end
39
+
40
+ array.each do |i|
41
+ if i.is_a?(Hash)
42
+ indifferent!(i)
43
+ elsif i.is_a?(Array)
44
+ indifferent_array!(i)
45
+ end
46
+ end
47
+ end
48
+
27
49
  #This method is called to convert all the keys of a hash into symbols to allow consistent usage of hashes within your Ruby application.
28
50
  def symbolize(hash)
29
51
  {}.tap do |h|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage One