Skip to content

Instantly share code, notes, and snippets.

@webgago
Created December 10, 2010 14:16
Show Gist options
  • Save webgago/736245 to your computer and use it in GitHub Desktop.
Save webgago/736245 to your computer and use it in GitHub Desktop.
convert_csv_to_yml
def convert_csv_to_yml
yaml = []
CSV.foreach('db/seeds/region.csv', {:col_sep => ';'}) do |row|
row[2] = row[2].force_encoding('UTF-8')
yaml << {:name => row[2], :region_id => row[0], :country_id => row[1]}
end
yaml.shift
File.open('db/seeds/regions.yml', 'w:UTF-8') { |f| f << unescape(YAML.dump(yaml)).force_encoding('UTF-8') }; nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment