Skip to content

Instantly share code, notes, and snippets.

@mattsnyder
Created April 26, 2013 21:04
Show Gist options
  • Save mattsnyder/5470445 to your computer and use it in GitHub Desktop.
Save mattsnyder/5470445 to your computer and use it in GitHub Desktop.
add BOM for UTF8
class FasterCSV
def <<(row)
# make sure headers have been assigned
if header_row? and [Array, String].include? @use_headers.class
parse_headers # won't read data for Array or String
self << @headers if @write_headers
end
# Handle FasterCSV::Row objects and Hashes
row = case row
when self.class::Row then row.fields
when Hash then @headers.map { |header| row[header] }
else row
end
@headers = row if header_row?
@lineno += 1
row[0] = "\357\273\277" + row[0] if @lineno == 1
@io << row.map(&@quote).join(@col_sep) + @row_sep # quote and separate
self # for chaining
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment