Skip to content

Instantly share code, notes, and snippets.

@codatory
Created September 12, 2011 16:30
Show Gist options
  • Save codatory/1211696 to your computer and use it in GitHub Desktop.
Save codatory/1211696 to your computer and use it in GitHub Desktop.
Chardet CSV Example
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment