Created
September 24, 2009 10:09
-
-
Save iwan/192655 to your computer and use it in GitHub Desktop.
Reading a csv file using FasterCSV
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
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
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