Created
December 10, 2010 14:16
-
-
Save webgago/736245 to your computer and use it in GitHub Desktop.
convert_csv_to_yml
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
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