diff options
author | Burdette Lamar <BurdetteLamar@Yahoo.com> | 2020-07-15 15:37:17 -0500 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-20 02:32:54 +0900 |
commit | d9749b4715168ccce020dd43b4815e365881f73e (patch) | |
tree | 45b6a98de91e0f33faff08262e82d241ec3ed055 /doc/csv/options/parsing/converters.rdoc | |
parent | d7c42df0b103fb24d39d5f52b792f21afa71daa7 (diff) |
[ruby/csv] RDoc for converters (#157)
* More on RDoc for converters
* More on RDoc for converters
* Fix indent
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
https://github.com/ruby/csv/commit/6044976160
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3332
Diffstat (limited to 'doc/csv/options/parsing/converters.rdoc')
-rw-r--r-- | doc/csv/options/parsing/converters.rdoc | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/doc/csv/options/parsing/converters.rdoc b/doc/csv/options/parsing/converters.rdoc index 993803c5d0..211fa48de6 100644 --- a/doc/csv/options/parsing/converters.rdoc +++ b/doc/csv/options/parsing/converters.rdoc @@ -1,41 +1,42 @@ ====== Option +converters+ -Specifies a single field converter name or \Proc, -or an \Array of field converter names and Procs. - +Specifies converters to be used in parsing fields. See {Field Converters}[#class-CSV-label-Field+Converters] Default value: CSV::DEFAULT_OPTIONS.fetch(:converters) # => nil -The value may be a single field converter name: +The value may be a field converter name +(see {Stored Converters}[#class-CSV-label-Stored+Converters]): str = '1,2,3' # Without a converter - ary = CSV.parse_line(str) - ary # => ["1", "2", "3"] + array = CSV.parse_line(str) + array # => ["1", "2", "3"] # With built-in converter :integer - ary = CSV.parse_line(str, converters: :integer) - ary # => [1, 2, 3] + array = CSV.parse_line(str, converters: :integer) + array # => [1, 2, 3] -The value may be an \Array of field converter names: +The value may be a converter list +(see {Converter Lists}[#class-CSV-label-Converter+Lists]): str = '1,3.14159' # Without converters - ary = CSV.parse_line(str) - ary # => ["1", "3.14159"] + array = CSV.parse_line(str) + array # => ["1", "3.14159"] # With built-in converters - ary = CSV.parse_line(str, converters: [:integer, :float]) - ary # => [1, 3.14159] + array = CSV.parse_line(str, converters: [:integer, :float]) + array # => [1, 3.14159] The value may be a \Proc custom converter: +(see {Custom Field Converters}[#class-CSV-label-Custom+Field+Converters]): str = ' foo , bar , baz ' # Without a converter - ary = CSV.parse_line(str) - ary # => [" foo ", " bar ", " baz "] + array = CSV.parse_line(str) + array # => [" foo ", " bar ", " baz "] # With a custom converter - ary = CSV.parse_line(str, converters: proc {|field| field.strip }) - ary # => ["foo", "bar", "baz"] + array = CSV.parse_line(str, converters: proc {|field| field.strip }) + array # => ["foo", "bar", "baz"] -See also {Custom Converters}[#class-CSV-label-Custom+Converters] +See also {Custom Field Converters}[#class-CSV-label-Custom+Field+Converters] --- |