6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/crazy_hash_filter.rb', line 6
def self.process(hash, rules)
rules = HashWithIndifferentAccess.new(rules || {}) unless rules.is_a?(HashWithIndifferentAccess)
child_rules = rules[:child_rules] || {}
result = {}
select = rules[:select].collect(&:to_sym) unless rules[:select].nil?
hash.each do |key, value|
next if !select.nil? && !select.include?(key.to_sym)
if child_rules[key].nil?
result[key] = value
else
if value.is_a?(Array)
result[key] = self.filter_array(value, child_rules[key])
else
result[key] = self.process(value, child_rules[key])
end
end
end
result
end
|