Method: Path.pathed

Defined in:
lib/path.rb

.pathed(data, escape = true) ⇒ Object

Returns a path-keyed data hash. Be careful of mixed key types in hashes as Symbols and Strings both use #to_s.

Path.pathed {'foo' => %w{thing bar}, 'fizz' => {'buzz' => 123}}
#=> {
#     '/foo/0' => 'thing',
#     '/foo/1' => 'bar',
#     '/fizz/buzz' => 123
#   }


140
141
142
143
144
145
146
147
148
149
150
# File 'lib/path.rb', line 140

def self.pathed data, escape=true
  new_data = {}

  find "**", data do |subdata, key, path|
    next if Array === subdata[key] || Hash === subdata[key]
    path_str = "#{DCH}#{join(path, escape)}"
    new_data[path_str] = subdata[key]
  end

  new_data
end