Skip to content

Instantly share code, notes, and snippets.

@codatory
Created September 12, 2011 16:30

Revisions

  1. Alex Conner created this gist Sep 12, 2011.
    8 changes: 8 additions & 0 deletions import.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    file = params[:csv].open
    chardet = CharDet.detect(file.read[0..200])
    if chardet['confidence'] > 0.7
    charset = chardet['encoding']
    else
    raise 'Unable to detect file encoding'
    end
    csv = CSV.parse(Iconv.conv('ASCII//IGNORE//TRANSLIT',charset,file.open.read), :headers => true)