This method will return the field value
by header or index. If
a field is not found, nil is
returned.
When provided, offset ensures that a header match occurs on or
later than the offsetindex.
You can use this to find duplicate headers, without resorting to
hard-coding exact indices.
# File lib/csv.rb, line 285
def field(header_or_index, minimum_index = 0)
# locate the pair
finder = (header_or_index.is_a?(Integer) || header_or_index.is_a?(Range)) ? :[] : :assoc
pair = @row[minimum_index..-1].send(finder, header_or_index)
# return the field if we have a pair
if pair.nil?
nil
else
header_or_index.is_a?(Range) ? pair.map(&:last) : pair.last
end
end