Module: Macmillan::Utils::Helper::HashKeyHelper
Instance Method Summary
collapse
camelcase_to_snakecase_symbol, snakecase_string, upper_camelcase_string
Instance Method Details
#convert_key_to_singular(key) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/macmillan/utils/helper/hash_key_helper.rb', line 36
def convert_key_to_singular(key)
if key.to_s == 'summaries'
:summary
else
key.to_s.chomp('s').to_sym
end
end
|
#convert_keys_to_snakecase_and_symbols(obj) ⇒ Object
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
|
# File 'lib/macmillan/utils/helper/hash_key_helper.rb', line 7
def convert_keys_to_snakecase_and_symbols(obj)
case obj
when Array
obj.reduce([]) do |res, val|
res << case val
when Hash, Array
convert_keys_to_snakecase_and_symbols(val)
else
val
end
res
end
when Hash
obj.reduce({}) do |res, (key, val)|
nkey = snakecase_string(key.to_s).to_sym
nval = case val
when Hash, Array
convert_keys_to_snakecase_and_symbols(val)
else
val
end
res[nkey] = nval
res
end
else
obj
end
end
|