hash_deep_search 0.0.1 → 0.0.2
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_deep_search.rb +20 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6412ba7a14fc72feffe44d5518416ca089802870
|
4
|
+
data.tar.gz: 87631dfe584d0ce8fb9c2c1e50d7ee854625f8ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac583f50bfb5dcef2cc53866a633d618db60f4d414f76a30aa1ac0010eec300612f25bed9e19cfb6d5538eba471fa8ce1e33123b4e2f4aefc202115e28ad7a7e
|
7
|
+
data.tar.gz: 834ddb2e17673616d6fdc9688a860503b2865a714256cb7781136e281c3c139d4997ecad2f56a622e27dff36f5e429048cfb2393f4e3909aa819720aa663ab4d
|
data/lib/hash_deep_search.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'byebug'
|
1
2
|
class HashDeepSearch
|
2
3
|
def initialize(hash)
|
3
4
|
@hash = hash
|
@@ -8,9 +9,25 @@ class HashDeepSearch
|
|
8
9
|
return {key_to_find => @hash[key_to_find]}
|
9
10
|
else
|
10
11
|
@hash.keys.each do |existing_key|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
case @hash[existing_key]
|
13
|
+
when Hash
|
14
|
+
search = HashDeepSearch.new(@hash[existing_key])
|
15
|
+
result = search.search(key_to_find)
|
16
|
+
return result if result.is_a?(Hash)
|
17
|
+
when Array
|
18
|
+
@hash[existing_key].each do |array_item|
|
19
|
+
case array_item
|
20
|
+
when Hash
|
21
|
+
search = HashDeepSearch.new(array_item)
|
22
|
+
result = search.search(key_to_find)
|
23
|
+
return result if result.is_a?(Hash)
|
24
|
+
else
|
25
|
+
next
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
next
|
30
|
+
end
|
14
31
|
end
|
15
32
|
end
|
16
33
|
end
|