Skip to content

Instantly share code, notes, and snippets.

@iwan
Created September 24, 2009 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwan/192655 to your computer and use it in GitHub Desktop.
Save iwan/192655 to your computer and use it in GitHub Desktop.
Reading a csv file using FasterCSV
namespace :dwh do
desc "bla bla"
task :import => :environment do
require 'fastercsv'
require 'iconv'
filepath = "Test.csv"
FasterCSV.foreach(filepath, {:col_sep => ";", :headers => true }) do |row|
puts ">>> #{row.inspect}"
puts ">>> #{row['First name'].to_utf8} - #{row['Last name'].to_utf8} - #{row[2].to_utf8}"
end
end
end
class String
def to_utf8
Iconv.conv("UTF-8", "MACROMAN", self)
end
end
class NilClass
def to_utf8
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment