Sha256: cd66ddf0171b98bc4a49516990f0424ed1a1fe2e95cf2bfb21e2e32f030a7680

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

====== Option +headers+

Specifies a boolean, \Symbol, \Array, or \String to be used
to define column headers.

Default value:
  CSV::DEFAULT_OPTIONS.fetch(:headers) # => false

---

Without +headers+:
  str = <<-EOT
  Name,Count
  foo,0
  bar,1
  bax,2
  EOT
  csv = CSV.new(str)
  csv # => #<CSV io_type:StringIO encoding:UTF-8 lineno:0 col_sep:"," row_sep:"\n" quote_char:"\"">
  csv.headers # => nil
  csv.shift # => ["Name", "Count"]

---

If set to +true+ or the \Symbol +:first_row+,
the first row of the data is treated as a row of headers:
  str = <<-EOT
  Name,Count
  foo,0
  bar,1
  bax,2
  EOT
  csv = CSV.new(str, headers: true)
  csv # => #<CSV io_type:StringIO encoding:UTF-8 lineno:2 col_sep:"," row_sep:"\n" quote_char:"\"" headers:["Name", "Count"]>
  csv.headers # => ["Name", "Count"]
  csv.shift # => #<CSV::Row "Name":"bar" "Count":"1">

---

If set to an \Array, the \Array elements are treated as headers:
  str = <<-EOT
  foo,0
  bar,1
  bax,2
  EOT
  csv = CSV.new(str, headers: ['Name', 'Count'])
  csv
  csv.headers # => ["Name", "Count"]
  csv.shift # => #<CSV::Row "Name":"bar" "Count":"1">

---

If set to a \String +str+, method <tt>CSV::parse_line(str, options)</tt> is called
with the current +options+, and the returned \Array is treated as headers:
  str = <<-EOT
  foo,0
  bar,1
  bax,2
  EOT
  csv = CSV.new(str, headers: 'Name,Count')
  csv
  csv.headers # => ["Name", "Count"]
  csv.shift # => #<CSV::Row "Name":"bar" "Count":"1">

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/parsing/headers.rdoc
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/parsing/headers.rdoc
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/parsing/headers.rdoc
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/parsing/headers.rdoc
csv-3.3.0 doc/csv/options/parsing/headers.rdoc
csv-3.2.9 doc/csv/options/parsing/headers.rdoc
csv-3.2.8 doc/csv/options/parsing/headers.rdoc
csv-3.2.7 doc/csv/options/parsing/headers.rdoc
csv-3.2.6 doc/csv/options/parsing/headers.rdoc
csv-3.2.5 doc/csv/options/parsing/headers.rdoc
csv-3.2.4 doc/csv/options/parsing/headers.rdoc
csv-3.2.3 doc/csv/options/parsing/headers.rdoc
csv-3.2.2 doc/csv/options/parsing/headers.rdoc
csv-3.2.1 doc/csv/options/parsing/headers.rdoc
csv-3.2.0 doc/csv/options/parsing/headers.rdoc
csv-3.1.9 doc/csv/options/parsing/headers.rdoc
csv-3.1.8 doc/csv/options/parsing/headers.rdoc
csv-3.1.7 doc/csv/options/parsing/headers.rdoc
csv-3.1.6 doc/options/parsing/headers.rdoc
csv-3.1.5 doc/headers.rdoc