Improve I18nContent#flat_hash readability using concise variable names

This commit is contained in:
Angel Perez
2018-08-20 10:43:57 -04:00
committed by decabeza
parent ae9cad3c5b
commit 4af5e1d46d

View File

@@ -40,10 +40,10 @@ class I18nContent < ActiveRecord::Base
# 'string.key2.key4.key5' => 'value3'
# }
def self.flat_hash(h, f = nil, g = {})
return g.update({ f => h }) unless h.is_a? Hash
h.map { |k, r| flat_hash(r, [f, k].compact.join('.'), g) }
return g
def self.flat_hash(input, path = nil, output = {})
return output.update({ path => input }) unless input.is_a? Hash
input.map { |key, value| flat_hash(value, [path, key].compact.join('.'), output) }
return output
end
end