Skip to content

Instantly share code, notes, and snippets.

@dforest
Created January 16, 2015 09:15
Show Gist options
  • Save dforest/f61c6cd426225b0b0570 to your computer and use it in GitHub Desktop.
Save dforest/f61c6cd426225b0b0570 to your computer and use it in GitHub Desktop.
Generate language.yml from csv
require 'csv'
require 'yaml'
csv = CSV.open(ARGV[0], 'r')
header = csv.take(1)[0]
hash = {}
language_ids = []
header.each_with_index do |language_id, index|
next if index == 0
hash[language_id] = {}
language_ids << language_id
end
csv.each do |row|
key = ""
row.each_with_index do |cell, index|
if index == 0
key = cell
else
language_id = language_ids[index-1]
hash[language_id][key] = cell
end
end
end
File.open('language.yml', 'w'){|f| f.write(hash.to_yaml) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment