Created
January 16, 2015 09:15
-
-
Save dforest/f61c6cd426225b0b0570 to your computer and use it in GitHub Desktop.
Generate language.yml from csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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