From 19efe1e37fe9929cfd3e5e152e09ffa1df2c0f9c Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Sun, 30 Aug 2026 10:31:14 +0200 Subject: [PATCH] Correct CSV option and recipe documentation --- doc/csv/options/common/quote_char.rdoc | 2 +- doc/csv/options/generating/write_headers.rdoc | 2 +- doc/csv/options/parsing/headers.rdoc | 9 +++++---- doc/csv/options/parsing/skip_blanks.rdoc | 2 +- doc/csv/options/parsing/skip_lines.rdoc | 6 ++++-- doc/csv/recipes/generating.rdoc | 14 +++++++------- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/doc/csv/options/common/quote_char.rdoc b/doc/csv/options/common/quote_char.rdoc index 67fd3af6..d6c42c48 100644 --- a/doc/csv/options/common/quote_char.rdoc +++ b/doc/csv/options/common/quote_char.rdoc @@ -1,6 +1,6 @@ ====== Option +quote_char+ -Specifies the character (\String of length 1) used used to quote fields +Specifies the character (\String of length 1) used to quote fields in both parsing and generating. This String will be transcoded into the data's \Encoding before use. diff --git a/doc/csv/options/generating/write_headers.rdoc b/doc/csv/options/generating/write_headers.rdoc index c56aa48a..d757911c 100644 --- a/doc/csv/options/generating/write_headers.rdoc +++ b/doc/csv/options/generating/write_headers.rdoc @@ -17,7 +17,7 @@ Without +write_headers+: csv.shift end # => ["foo", "0"] -With +write_headers+": +With +write_headers+: CSV.open(file_path,'w', :write_headers => true, :headers => ['Name','Value'] diff --git a/doc/csv/options/parsing/headers.rdoc b/doc/csv/options/parsing/headers.rdoc index 0ea151f2..2fc7c1e7 100644 --- a/doc/csv/options/parsing/headers.rdoc +++ b/doc/csv/options/parsing/headers.rdoc @@ -31,9 +31,10 @@ the first row of the data is treated as a row of headers: bax,2 EOT csv = CSV.new(str, headers: true) - csv # => # + csv # => # + csv.headers # => true + csv.shift # => # csv.headers # => ["Name", "Count"] - csv.shift # => # --- @@ -46,7 +47,7 @@ If set to an \Array, the \Array elements are treated as headers: csv = CSV.new(str, headers: ['Name', 'Count']) csv csv.headers # => ["Name", "Count"] - csv.shift # => # + csv.shift # => # --- @@ -60,4 +61,4 @@ with the current +options+, and the returned \Array is treated as headers: csv = CSV.new(str, headers: 'Name,Count') csv csv.headers # => ["Name", "Count"] - csv.shift # => # + csv.shift # => # diff --git a/doc/csv/options/parsing/skip_blanks.rdoc b/doc/csv/options/parsing/skip_blanks.rdoc index 2c8f7b7b..02f9b18a 100644 --- a/doc/csv/options/parsing/skip_blanks.rdoc +++ b/doc/csv/options/parsing/skip_blanks.rdoc @@ -6,7 +6,7 @@ a line that contains a column separator is not considered to be blank. Default value: CSV::DEFAULT_OPTIONS.fetch(:skip_blanks) # => false -See also option {skiplines}[#class-CSV-label-Option+skip_lines]. +See also option {skip_lines}[#class-CSV-label-Option+skip_lines]. For examples in this section: str = <<-EOT diff --git a/doc/csv/options/parsing/skip_lines.rdoc b/doc/csv/options/parsing/skip_lines.rdoc index 1481c40a..b59f338c 100644 --- a/doc/csv/options/parsing/skip_lines.rdoc +++ b/doc/csv/options/parsing/skip_lines.rdoc @@ -2,8 +2,9 @@ Specifies an object to use in identifying comment lines in the input that are to be ignored: * If a \Regexp, ignores lines that match it. -* If a \String, converts it to a \Regexp, ignores lines that match it. +* If a \String, ignores lines that include it. * If +nil+, no lines are considered to be comments. +* Otherwise, the object must respond to +match+; ignores lines for which +match+ returns a truthy value. Default value: CSV::DEFAULT_OPTIONS.fetch(:skip_lines) # => nil @@ -32,6 +33,7 @@ Using a \String: --- -Raises an exception if given an object that is not a \Regexp, a \String, or +nil+: +Raises an exception if given an object that is not a \Regexp, a \String, +nil+, +or an object that responds to +match+: # Raises ArgumentError (:skip_lines has to respond to #match: 0) CSV.parse(str, skip_lines: 0) diff --git a/doc/csv/recipes/generating.rdoc b/doc/csv/recipes/generating.rdoc index d96ff85c..ce599d98 100644 --- a/doc/csv/recipes/generating.rdoc +++ b/doc/csv/recipes/generating.rdoc @@ -16,7 +16,7 @@ All code snippets on this page assume that the following has been executed: - {Generating to a File}[#label-Generating+to+a+File] - {Recipe: Generate to File with Headers}[#label-Recipe-3A+Generate+to+File+with+Headers] - {Recipe: Generate to File Without Headers}[#label-Recipe-3A+Generate+to+File+Without+Headers] - - {Generating to IO an Stream}[#label-Generating+to+an+IO+Stream] + - {Generating to an IO Stream}[#label-Generating+to+an+IO+Stream] - {Recipe: Generate to IO Stream with Headers}[#label-Recipe-3A+Generate+to+IO+Stream+with+Headers] - {Recipe: Generate to IO Stream Without Headers}[#label-Recipe-3A+Generate+to+IO+Stream+Without+Headers] - {Converting Fields}[#label-Converting+Fields] @@ -71,11 +71,11 @@ that are to be generated: ==== Generating to a \File -You can generate /CSV data to a \File, with or without headers. +You can generate \CSV data to a \File, with or without headers. ===== Recipe: Generate to \File with Headers -Use class method CSV.open with option +headers+ generate to a \File. +Use class method CSV.open with option +headers+ to generate to a \File. This example uses method CSV#<< to append the rows that are to be generated: @@ -105,7 +105,7 @@ that are to be generated: You can generate \CSV data to an \IO stream, with or without headers. -==== Recipe: Generate to \IO Stream with Headers +===== Recipe: Generate to \IO Stream with Headers Use class method CSV.new with option +headers+ to generate \CSV data to an \IO stream: path = 't.csv' @@ -187,7 +187,7 @@ For strict compliance, use option +:row_sep+ to specify row separator "\r\n" ===== Recipe: Generate Non-Compliant Row Separator For data with non-compliant row separators, use option +:row_sep+ with a different value: -This example source uses semicolon (";') as its row separator: +This example source uses semicolon (";") as its row separator: output_string = CSV.generate('', row_sep: ";") do |csv| csv << ['Foo', 0] csv << ['Bar', 1] @@ -223,11 +223,11 @@ This example source uses TAB ("\t") as its column separator: ==== Quotes -IFC 4180 allows most fields to be quoted or not. +RFC 4180 allows most fields to be quoted or not. By default, \CSV does not quote most fields. However, a field containing the current row separator, column separator, -or quote character is automatically quoted, producing IFC 4180 compliance: +or quote character is automatically quoted, producing RFC 4180 compliance: # Field contains row separator. output_string = CSV.generate('') do |csv| row_sep = csv.row_sep