Created
September 12, 2011 16:30
-
-
Save codatory/1211696 to your computer and use it in GitHub Desktop.
Chardet CSV Example
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
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