Skip to content

Instantly share code, notes, and snippets.

@dmacvicar
Created March 3, 2012 21:48
Show Gist options
  • Save dmacvicar/1968448 to your computer and use it in GitHub Desktop.
Save dmacvicar/1968448 to your computer and use it in GitHub Desktop.
def expand_keys(key, value)
if File.dirname(key) != "/"
return expand_keys(File.dirname(key), { File.basename(key) => value })
else
return {File.dirname(key) => { File.basename(key) => value }}
end
end
data = {
"unpacked" => {
".files" => {
"mime" => "text/plain",
"sha256" => "uzgc7EfJR9tYpyNn4r8FSWfNahxPdsJBG7Gs9rhlQiY"
},
".ldig-unpack.pid" => {
"mime" => "text/plain",
"sha256" => "3oBDw7Sl4mtSlot8006M5tuKen+fq7ihmnPOhzYmlEw"
},
".origin" => {
"mime" => "text/plain",
"sha256" => "EkLHkyBEpI6hQlsz7pdLXjKSvH0RBgpXfaHSniN+rRw"
},
"_service" => {
"mime" => "application/xml",
"sha256" => "0S_tvzccZNdH7EA9cWZ6VKOaVCiy5dxnjz61efbKhsk"
}
}
}
final = data["unpacked"].map do |k, v|
expand_keys(File.expand_path(k), v)
end
require 'pp'
pp final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment