summaryrefslogtreecommitdiff
path: root/doc/csv/options/parsing/unconverted_fields.rdoc
blob: 3e7f839d49563dde813ddd588f41ec4bc71b06eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
====== Option +unconverted_fields+

Specifies the boolean that determines whether unconverted field values are to be available.

Default value:
  CSV::DEFAULT_OPTIONS.fetch(:unconverted_fields) # => nil

The unconverted field values are those found in the source data,
prior to any conversions performed via option +converters+.

When option +unconverted_fields+ is +true+,
each returned row (\Array or \CSV::Row) has an added method,
+unconverted_fields+, that returns the unconverted field values:
  str = <<-EOT
  foo,0
  bar,1
  baz,2
  EOT
  # Without unconverted_fields
  csv = CSV.parse(str, converters: :integer)
  csv # => [["foo", 0], ["bar", 1], ["baz", 2]]
  csv.first.respond_to?(:unconverted_fields) # => false
  # With unconverted_fields
  csv = CSV.parse(str, converters: :integer, unconverted_fields: true)
  csv # => [["foo", 0], ["bar", 1], ["baz", 2]]
  csv.first.respond_to?(:unconverted_fields) # => true
  csv.first.unconverted_fields # => ["foo", "0"]