<<(row)
public
The primary write method for wrapped Strings and IOs, row (an Array or CSV::Row) is
converted to CSV and appended to the data source.
When a CSV::Row is passed, only the row’s
fields() are appended to the output.
The data source must be open for
writing.
Show source
def <<(row)
if header_row? and [Array, String].include? @use_headers.class
parse_headers
self << @headers if @write_headers
end
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
output = row.map(&@quote).join(@col_sep) + @row_sep
if @io.is_a?(StringIO) and
output.encoding != (encoding = raw_encoding)
if @force_encoding
output = output.encode(encoding)
elsif (compatible_encoding = Encoding.compatible?(@io.string, output))
@io.set_encoding(compatible_encoding)
@io.seek(0, IO::SEEK_END)
end
end
@io << output
self
end