hash_kit 0.2.0 → 0.3.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 +39 -0
- 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: 8ee3250a09196525abfd3814922a0a6c85c22fa3
|
4
|
+
data.tar.gz: 638b1c120f32907fafec0c7a1349ce3790469285
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51003a9f4fa9b2b0cfb38a0ed0ad098edd72a73bc4f016c4355c652cd7595107b2023c28afd14ab9193f0939aa5cfbf5846588f001e372c64cce9c1fc8134c53
|
7
|
+
data.tar.gz: d5e823bff9c350eba79b87eaa4e2743cdc706319b307971d72ef6e96f6dcebd10d21d6938ae5f5e2d2859ada75745bf0f0e20e163e7edc33b052d77a4848c320
|
data/lib/hash_kit/helper.rb
CHANGED
@@ -15,8 +15,47 @@ module HashKit
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def to_hash(obj)
|
19
|
+
hash = {}
|
20
|
+
obj.instance_variables.each do |key|
|
21
|
+
hash[key[1..-1].to_sym] = deeply_to_hash(obj.instance_variable_get(key))
|
22
|
+
end
|
23
|
+
hash
|
24
|
+
end
|
25
|
+
|
18
26
|
private
|
19
27
|
|
28
|
+
# nodoc
|
29
|
+
def convert_hash_values(hash)
|
30
|
+
new_hash = {}
|
31
|
+
hash.each do |key, val|
|
32
|
+
new_hash[key] = deeply_to_hash(val)
|
33
|
+
end
|
34
|
+
new_hash
|
35
|
+
end
|
36
|
+
|
37
|
+
# nodoc
|
38
|
+
def convert_array_values(array)
|
39
|
+
new_array = []
|
40
|
+
array.each_index do |index|
|
41
|
+
new_array[index] = deeply_to_hash(array[index])
|
42
|
+
end
|
43
|
+
new_array
|
44
|
+
end
|
45
|
+
|
46
|
+
# nodoc
|
47
|
+
def deeply_to_hash(val)
|
48
|
+
if val.is_a?(Hash)
|
49
|
+
return convert_hash_values(val)
|
50
|
+
elsif val.is_a?(Array)
|
51
|
+
return convert_array_values(val)
|
52
|
+
elsif [String, Fixnum, Numeric, Date, DateTime, Time, Integer].include?(val.class)
|
53
|
+
val
|
54
|
+
else
|
55
|
+
return to_hash(val)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
20
59
|
def map_value_symbol(thing)
|
21
60
|
case thing
|
22
61
|
when Hash
|
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.3.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-
|
11
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|