hash_deep_search 0.0.1 → 0.0.2

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_deep_search.rb +20 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc0b21e5faae1746947f891e397946297c706720
4
- data.tar.gz: 26abb1808788b3e3bc2b328312a2d1e18f6b179b
3
+ metadata.gz: 6412ba7a14fc72feffe44d5518416ca089802870
4
+ data.tar.gz: 87631dfe584d0ce8fb9c2c1e50d7ee854625f8ae
5
5
  SHA512:
6
- metadata.gz: 881a52c52d9bf61d433087ee6b423819a9b9af31217b0a3b4dccde0fb980c771e948deb7b7742c77359d3e731696fbf2a168e7599ded923e47a83b5932cc4ec0
7
- data.tar.gz: 8f6b53a4babca35047a4cf48d06ab62fa805d18e01f1440cbf86532101498a58134782dc0fa60f422444cf5f393d37c43aa83a75a11138e055532effcd8a7b4a
6
+ metadata.gz: ac583f50bfb5dcef2cc53866a633d618db60f4d414f76a30aa1ac0010eec300612f25bed9e19cfb6d5538eba471fa8ce1e33123b4e2f4aefc202115e28ad7a7e
7
+ data.tar.gz: 834ddb2e17673616d6fdc9688a860503b2865a714256cb7781136e281c3c139d4997ecad2f56a622e27dff36f5e429048cfb2393f4e3909aa819720aa663ab4d
@@ -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
- next unless @hash[existing_key].is_a?(Hash)
12
- search = HashDeepSearch.new(@hash[existing_key])
13
- return search.search(key_to_find)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_deep_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Korfmann