Created
April 26, 2013 21:04
-
-
Save mattsnyder/5470445 to your computer and use it in GitHub Desktop.
add BOM for UTF8
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
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