Created
April 26, 2012 12:13
-
-
Save ka8725/2499187 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require "csv_corrector/version" | |
require "tempfile" | |
module CsvCorrector | |
def correct(file_path) | |
temp = Tempfile.new([File.basename(file_path, '.*'), '.csv'], File.dirname(file_path)) | |
begin | |
File.open(file_path) do |file| | |
file.each do |line| | |
line.gsub!(/"(.*?)"\,/).each { |m| %Q["#{$1.gsub /"/, "'"}",] } | |
temp << line | |
end | |
end | |
temp.rewind | |
rescue | |
return false | |
ensure | |
temp.close | |
temp.unlink | |
end | |
true | |
end | |
module_function :correct | |
end |
Author
ka8725
commented
Apr 26, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment