Sha256: ead4cea9c060cb31654000b996648e7bfb7d4ae1e3a7e79be496068d5a972013

Contents?: true

Size: 1.36 KB

Versions: 23

Compression:

Stored size: 1.36 KB

Contents

====== Option +quote_char+

Specifies the character (\String of length 1) used used to quote fields
in both parsing and generating.
This String will be transcoded into the data's \Encoding before use.

Default value:
  CSV::DEFAULT_OPTIONS.fetch(:quote_char) # => "\"" (double quote)

This is useful for an application that incorrectly uses <tt>'</tt> (single-quote)
to quote fields, instead of the correct <tt>"</tt> (double-quote).

Using the default (double quote):
  str = CSV.generate do |csv|
    csv << ['foo', 0]
    csv << ["'bar'", 1]
    csv << ['"baz"', 2]
  end
  str # => "foo,0\n'bar',1\n\"\"\"baz\"\"\",2\n"
  ary = CSV.parse(str)
  ary # => [["foo", "0"], ["'bar'", "1"], ["\"baz\"", "2"]]

Using <tt>'</tt> (single-quote):
  quote_char = "'"
  str = CSV.generate(quote_char: quote_char) do |csv|
    csv << ['foo', 0]
    csv << ["'bar'", 1]
    csv << ['"baz"', 2]
  end
  str # => "foo,0\n'''bar''',1\n\"baz\",2\n"
  ary = CSV.parse(str, quote_char: quote_char)
  ary # => [["foo", "0"], ["'bar'", "1"], ["\"baz\"", "2"]]

---

Raises an exception if the \String length is greater than 1:
  # Raises ArgumentError (:quote_char has to be nil or a single character String)
  CSV.new('', quote_char: 'xx')

Raises an exception if the value is not a \String:
  # Raises ArgumentError (:quote_char has to be nil or a single character String)
  CSV.new('', quote_char: :foo)

Version data entries

23 entries across 22 versions & 5 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/csv-3.3.0/doc/csv/options/common/quote_char.rdoc
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/common/quote_char.rdoc
csv-3.3.2 doc/csv/options/common/quote_char.rdoc
csv-3.3.1 doc/csv/options/common/quote_char.rdoc
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/common/quote_char.rdoc
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/common/quote_char.rdoc
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/common/quote_char.rdoc
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/csv-3.3.0/doc/csv/options/common/quote_char.rdoc
csv-3.3.0 doc/csv/options/common/quote_char.rdoc
csv-3.2.9 doc/csv/options/common/quote_char.rdoc
csv-3.2.8 doc/csv/options/common/quote_char.rdoc
csv-3.2.7 doc/csv/options/common/quote_char.rdoc
csv-3.2.6 doc/csv/options/common/quote_char.rdoc
csv-3.2.5 doc/csv/options/common/quote_char.rdoc
csv-3.2.4 doc/csv/options/common/quote_char.rdoc
csv-3.2.3 doc/csv/options/common/quote_char.rdoc
csv-3.2.2 doc/csv/options/common/quote_char.rdoc
csv-3.2.1 doc/csv/options/common/quote_char.rdoc
csv-3.2.0 doc/csv/options/common/quote_char.rdoc
csv-3.1.9 doc/csv/options/common/quote_char.rdoc