| Description: |
Ruby library to parse or generate data in CSV format.
Attached unit test covers 99.8% of source code line.
CVS: http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/lib/csv/
- Changes in 1.2.2 (September 15, 2003 - version 1.2.2)
Add extra pamameter to specify row(record) separater character. To parse
Mac's CR separated CSV, do like this.
CSV.open("mac.csv", "r", ?,, ?\r) { |row| p row.to_a }
The 3rd parameter in this example ?, is for column separater and the 4th
?\r is for row separater. Row separater is nil by default. Nil separater
means "\r\n" or "\n".
- Changes in 1.2.1 (January 11, 2003 - version 1.2.1)
Let CSV::Reader include Enumerable. This one line adding is the difference.
- What is 'CSV'?
CSV: Comma Separated Value.
In http://www.wotsit.org/, CSV is defined as follows.
<CSV_file> ::= { <CSV_line> }
<CSV_line> ::= <value> { "," <value> } <spaces_and_tabs> <CRLF>
<value> ::= <spaces_and_tabs>
(
{ <any_text_except_quotas_and_commas_and_smth_else> }
| <single_or_double_quote>
<any_text_save_CRLF_with_corresponding_doubled_quotas>
<the_same_quote>
)
[...]
... and there is some problem with this format:
different database systems have different definitions of the
term <any_text_except_quotas_and_commas_and_smth_else> :)
So, I defined CSV format, in my module, as follows. Fortunately, this is
compatible with Microsoft's Excel(at least Excel '97 or later),
and other applications like spread-sheets, DB, and so on.
Record separator: CR + LF
Field separator: ,(comma) by default; configurable
Quote data like "..." if contains CR, LF, or ,(comma).
Convert " -> "" when quoted.
Field "" means null string. ( ex. some-data,"",some-data )
Field which has no data means NULL. ( ex. some-data,,some-data )
|