hash_kit 0.1.0 → 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/lib/hash_kit/helper.rb +21 -3
- data/lib/hash_kit/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: cbfcb56f129d09473358ec32ebe9df25f4509345
|
|
4
|
+
data.tar.gz: 7e4be22e348d2685448e078283cca6dbc6c2348d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2f9d165d696ec7614f426ad94547f968e1fde87c9135b080dc11b1063598bd84f09ea59bd070533afd2c06feb24650ece5cfb6ed713c215b9126369431e8a6c
|
|
7
|
+
data.tar.gz: 6dae70e009933b127cdc641a01c1e91567003f72031f41d800f4f0ab7aad88b01c2dc769ef0781d9faafe785deaad5712cbc34bbd4708c39952239638f0d5cc8
|
data/lib/hash_kit/helper.rb
CHANGED
|
@@ -4,18 +4,36 @@ module HashKit
|
|
|
4
4
|
#This method is called to convert all the keys of a hash into symbols to allow consistent usage of hashes within your Ruby application.
|
|
5
5
|
def symbolize(hash)
|
|
6
6
|
{}.tap do |h|
|
|
7
|
-
hash.each { |key, value| h[key.to_sym] =
|
|
7
|
+
hash.each { |key, value| h[key.to_sym] = map_value_symbol(value) }
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
#This method is called to convert all the keys of a hash into strings to allow consistent usage of hashes within your Ruby application.
|
|
12
|
+
def stringify(hash)
|
|
13
|
+
{}.tap do |h|
|
|
14
|
+
hash.each { |key, value| h[key.to_s] = map_value_string(value) }
|
|
8
15
|
end
|
|
9
16
|
end
|
|
10
17
|
|
|
11
18
|
private
|
|
12
19
|
|
|
13
|
-
def
|
|
20
|
+
def map_value_symbol(thing)
|
|
14
21
|
case thing
|
|
15
22
|
when Hash
|
|
16
23
|
symbolize(thing)
|
|
17
24
|
when Array
|
|
18
|
-
thing.map { |v|
|
|
25
|
+
thing.map { |v| map_value_symbol(v) }
|
|
26
|
+
else
|
|
27
|
+
thing
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def map_value_string(thing)
|
|
32
|
+
case thing
|
|
33
|
+
when Hash
|
|
34
|
+
stringify(thing)
|
|
35
|
+
when Array
|
|
36
|
+
thing.map { |v| map_value_string(v) }
|
|
19
37
|
else
|
|
20
38
|
thing
|
|
21
39
|
end
|
data/lib/hash_kit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hash_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- vaughanbrittonsage
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-06-
|
|
11
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|