This method is used to turn a finished row into a CSV::Row. Header rows are also dealt with here,
either by returning a CSV::Row with identical
headers and fields (save that the fields do
not go through the converters) or by
reading past them to return a field row. Headers are also saved in @headers for use in future rows.
When nil,row is assumed to be a header row not based on
an actual row of the stream.
# File lib/csv.rb, line 2250
def parse_headers(row = nil)
if @headers.nil? # header row
@headers = case @use_headers # save headers
# Array of headers
when Array then @use_headers
# CSV header String
when String
self.class.parse_line( @use_headers,
col_sep: @col_sep,
row_sep: @row_sep,
quote_char: @quote_char )
# first row is headers
else row
end
# prepare converted and unconverted copies
row = @headers if row.nil?
@headers = convert_fields(@headers, true)
if @return_headers # return headers
return self.class::Row.new(@headers, row, true)
elsif not [Array, String].include? @use_headers.class # skip to field row
return shift
end
end
self.class::Row.new(@headers, convert_fields(row)) # field row
end