hash_ext 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash_ext/normalized.rb +17 -1
- data/lib/hash_ext/version.rb +1 -1
- 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: eba87bb627d260913baffdb6da736ed155ccef99
|
4
|
+
data.tar.gz: f44ace55737bf6249643940f8fea149bc176c7be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6071d9756d9ca39ba7bcd151b32e357fdc454c010de8938c6680ce17cbace13386095b1cc6a7a813270dd0cc14c318af617fa1fb7d18e5a7d0aa67ed90cb03c4
|
7
|
+
data.tar.gz: 773ca805d092b144470489a2cd931cc515b5efa79c2b83afe345658171009da156056ae174ad33abdfb3d4c769650dc3aeb3e1bf8996f6cb49447d34870b90d1
|
data/lib/hash_ext/normalized.rb
CHANGED
@@ -30,7 +30,7 @@ class Hash
|
|
30
30
|
def update(hash, &block)
|
31
31
|
hash.each do |key, value|
|
32
32
|
new_val = block && key?(key) ? block.call(key, self[key], value) : value
|
33
|
-
store
|
33
|
+
store key, new_val
|
34
34
|
end
|
35
35
|
self
|
36
36
|
end
|
@@ -51,6 +51,12 @@ class Hash
|
|
51
51
|
super normalize_key(key), *args, &block
|
52
52
|
end
|
53
53
|
|
54
|
+
def to_h
|
55
|
+
each_with_object({}) do |(key, value), hash|
|
56
|
+
hash[key] = value_to_h value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
54
60
|
private
|
55
61
|
|
56
62
|
def normalize_key(key)
|
@@ -67,5 +73,15 @@ class Hash
|
|
67
73
|
end
|
68
74
|
end
|
69
75
|
|
76
|
+
def value_to_h(value)
|
77
|
+
if value.kind_of? Hash
|
78
|
+
value.to_h
|
79
|
+
elsif value.kind_of? Array
|
80
|
+
value.map { |v| value_to_h v }
|
81
|
+
else
|
82
|
+
value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
70
86
|
end
|
71
87
|
end
|
data/lib/hash_ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|