4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/zaws/helper/process_hash.rb', line 4
def self.keep(target, list_of_strings)
result=''
if target.instance_of?(Hash)
target.each do |k, v|
list_of_strings.each do |x|
if k.downcase.include? x.downcase
result = {} if result.eql?('')
result[k]=v
end
end
if result.eql?('')
recurse=self.keep(v, list_of_strings)
end
if !recurse.nil? and !recurse.eql?('')
result = {} if result.eql?('')
result[k]=recurse
end
end
end
if target.instance_of?(String)
list_of_strings.each do |x|
if target.downcase.include? x.downcase
result=target
end
end
end
if target.instance_of?(Array)
target.each do |y|
iterate=self.keep(y, list_of_strings)
if !iterate.nil? and !iterate.eql?('')
result = [] if result.eql?('')
result << iterate
end
end
end
if result.nil?
return ''
end
return result
end
|