Skip to content

Instantly share code, notes, and snippets.

@ryonext
Last active August 29, 2015 14:02
Show Gist options
  • Save ryonext/9ce76ba7d92464b41656 to your computer and use it in GitHub Desktop.
Save ryonext/9ce76ba7d92464b41656 to your computer and use it in GitHub Desktop.
yaml2csv
require 'yaml'
def read_hash(hash, path, f)
hash.keys.each do |k|
val = hash[k]
if val.class == Hash
read_hash(val, path + k + ".", f)
else
f.write "\"#{path}#{k}\",\"#{val}\"\n"
end
end
end
root = YAML.load_file('en.yml')
if root.class == Hash
f = open("out.csv", "w")
read_hash(root["en"], "", f)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment