Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/csv/options/common/quote_char.rdoc
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion doc/csv/options/generating/write_headers.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
9 changes: 5 additions & 4 deletions doc/csv/options/parsing/headers.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 io_type:StringIO encoding:UTF-8 lineno:2 col_sep:"," row_sep:"\n" quote_char:"\"" headers:["Name", "Count"]>
csv # => #<CSV io_type:StringIO encoding:UTF-8 lineno:0 col_sep:"," row_sep:"\n" quote_char:"\"" headers:true>
csv.headers # => true
csv.shift # => #<CSV::Row "Name":"foo" "Count":"0">
csv.headers # => ["Name", "Count"]
csv.shift # => #<CSV::Row "Name":"bar" "Count":"1">

---

Expand All @@ -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::Row "Name":"bar" "Count":"1">
csv.shift # => #<CSV::Row "Name":"foo" "Count":"0">

---

Expand All @@ -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::Row "Name":"bar" "Count":"1">
csv.shift # => #<CSV::Row "Name":"foo" "Count":"0">
2 changes: 1 addition & 1 deletion doc/csv/options/parsing/skip_blanks.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions doc/csv/options/parsing/skip_lines.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
14 changes: 7 additions & 7 deletions doc/csv/recipes/generating.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -187,7 +187,7 @@ For strict compliance, use option +:row_sep+ to specify row separator <tt>"\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 (<tt>";'</tt>) as its row separator:
This example source uses semicolon (<tt>";"</tt>) as its row separator:
output_string = CSV.generate('', row_sep: ";") do |csv|
csv << ['Foo', 0]
csv << ['Bar', 1]
Expand Down Expand Up @@ -223,11 +223,11 @@ This example source uses TAB (<tt>"\t"</tt>) 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
Expand Down