Module: HashArrayFlatten
- Defined in:
- lib/hash_array_flatten.rb,
lib/hash_array_flatten/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
Class Method Details
.visit(data, current_key = nil, result = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hash_array_flatten.rb', line 4 def self.visit(data, current_key = nil, result = {}) if data.is_a?(Hash) data.keys.map {|key| visit(data[key], [current_key, key].compact.join("."), result)} elsif data.is_a?(Array) # TODO refactor converted = data.map.with_index.inject({}){|hash, (v, i)| hash[i] = v; hash } converted.keys.map {|key| visit(converted[key], [current_key, key].compact.join("."), result)} else result[current_key] = data end result end |