Method: TableImporter::CSV#clean_file

Defined in:
lib/table_importer/csv.rb

#clean_file(file) ⇒ Object



165
166
167
168
169
170
171
172
173
174
# File 'lib/table_importer/csv.rb', line 165

def clean_file(file)
  contents = file.read
  import = Tempfile.new(["import", ".xls"], :encoding => "UTF-8")
  utf8_content = contents.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace, :replace => '?').encode('UTF-8').gsub(/\r\n|\r/, "\n").squeeze("\n")
  clean_contents = utf8_content[0] == "\n" ? utf8_content[1..-1] : utf8_content
  import.write(clean_contents)
  import.close
  reset_separators
  return import
end