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
|
# File 'lib/better_params/base/strip_values.rb', line 4
def strip_values(*keys)
keys.reduce(self) do |result, key|
if key.is_a?(Hash)
key.reduce(result) do |hash_result, (hash_key, hash_value)|
next hash_result unless hash_result.key?(hash_key)
nested = hash_result[hash_key]
next hash_result if nested.nil?
nested =
if nested.is_a?(Array)
nested.map do |nested_object|
nested_object.strip_values(*hash_value)
end
else
nested.strip_values(*hash_value)
end
hash_result.merge(hash_key => nested)
end
else
next result unless result.key?(key)
result.merge(key => result[key]&.strip)
end
end
end
|