U:RDoc::NormalClass[iI"CSV:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[;o:RDoc::Markup::Paragraph;[I"PThis class provides a complete interface to CSV files and data. It offers ;TI"Qtools to enable you to read and write to and from Strings or IO objects, as ;TI"needed.;To:RDoc::Markup::BlankLine S:RDoc::Markup::Heading:
leveli: textI"Reading;T@S;;i;
I"From a File;T@S;;i ;
I"A Line at a Time;T@o:RDoc::Markup::Verbatim;[I".CSV.foreach("path/to/file.csv") do |row|
;TI" # use row here...
;TI" end
;T:@format0S;;i ;
I"All at Once;T@o;;[I"0arr_of_arrs = CSV.read("path/to/file.csv")
;T;0S;;i;
I"From a String;T@S;;i ;
I"A Line at a Time;T@o;;[I"+CSV.parse("CSV,data,String") do |row|
;TI" # use row here...
;TI" end
;T;0S;;i ;
I"All at Once;T@o;;[I"0arr_of_arrs = CSV.parse("CSV,data,String")
;T;0S;;i;
I"Writing;T@S;;i;
I"To a File;T@o;;[
I"1CSV.open("path/to/file.csv", "wb") do |csv|
;TI"+ csv << ["row", "of", "CSV", "data"]
;TI"! csv << ["another", "row"]
;TI"
# ...
;TI" end
;T;0S;;i;
I"To a String;T@o;;[
I"(csv_string = CSV.generate do |csv|
;TI"+ csv << ["row", "of", "CSV", "data"]
;TI"! csv << ["another", "row"]
;TI"
# ...
;TI" end
;T;0S;;i;
I"Convert a Single Line;T@o;;[I"4csv_string = ["CSV", "data"].to_csv # to CSV
;TI"6csv_array = "CSV,String".parse_csv # from CSV
;T;0S;;i;
I"Shortcut Interface;T@o;;[ I"MCSV { |csv_out| csv_out << %w{my data here} } # to $stdout
;TI"NCSV(csv = "") { |csv_str| csv_str << %w{my data here} } # to a String
;TI"MCSV($stderr) { |csv_err| csv_err << %w{my data here} } # to $stderr
;TI"NCSV($stdin) { |csv_in| csv_in.each { |row| p row } } # from $stdin
;T;0S;;i;
I"Advanced Usage;T@S;;i;
I"Wrap an IO Object;T@o;;[I" csv = CSV.new(io, options)
;TI"Q# ... read (with gets() or each()) from and write (with <<) to csv here ...
;T;0S;;i;
I">CSV and Character Encodings (M17n or Multilingualization);T@o; ;[I"TThis new CSV parser is m17n savvy. The parser works in the Encoding of the IO ;TI"Tor String object being read from or written to. Your data is never transcoded ;TI"S(unless you ask Ruby to transcode it for you) and will literally be parsed in ;TI"Sthe Encoding it is in. Thus CSV will return Arrays or Rows of Strings in the ;TI"SEncoding of your data. This is accomplished by transcoding the parser itself ;TI"into your Encoding.;T@o; ;[I"SSome transcoding must take place, of course, to accomplish this multiencoding ;TI"Fsupport. For example, :col_sep, :row_sep, and ;TI"Q:quote_char must be transcoded to match your data. Hopefully this ;TI"Qmakes the entire process feel transparent, since CSV's defaults should just ;TI"Rmagically work for your data. However, you can set these values manually in ;TI"2the target Encoding to avoid the translation.;T@o; ;[I"LIt's also important to note that while all of CSV's core parser is now ;TI"JEncoding agnostic, some features are not. For example, the built-in ;TI"Oconverters will try to transcode data to UTF-8 before making conversions. ;TI"RAgain, you can provide custom converters that are aware of your Encodings to ;TI"Javoid this translation. It's just too hard for me to support native ;TI",conversions in all of Ruby's Encodings.;T@o; ;[ I"TAnyway, the practical side of this is simple: make sure IO and String objects ;TI"Spassed into CSV have the proper Encoding set and everything should just work. ;TI"QCSV methods that allow you to open IO objects (CSV::foreach(), CSV::open(), ;TI"MCSV::read(), and CSV::readlines()) do allow you to specify the Encoding.;T@o; ;[
I"ROne minor exception comes when generating CSV into a String with an Encoding ;TI"Othat is not ASCII compatible. There's no existing data for CSV to use to ;TI"Tprepare itself and thus you will probably need to manually specify the desired ;TI"SEncoding for most of those cases. It will try to guess using the fields in a ;TI"Mrow of output though, when using CSV::generate_line() or Array#to_csv().;T@o; ;[I"RI try to point out any other Encoding issues in the documentation of methods ;TI"as they come up.;T@o; ;[ I"SThis has been tested to the best of my ability with all non-"dummy" Encodings ;TI"MRuby ships with. However, it is brave new code and may have some bugs. ;TI"SPlease feel free to {report}[mailto:james@grayproductions.net] any issues you ;TI"find with it.;T:
@fileI"lib/csv.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[
I"col_sep;TI"R;T:publicFI"lib/csv.rb;T[
I"
encoding;TI"R;T;F@Œ[
I"field_size_limit;TI"R;T;F@Œ[
I"lineno;TI"R;T;F@Œ[
I"quote_char;TI"R;T;F@Œ[
I"row_sep;TI"R;T;F@Œ[
I"skip_lines;TI"R;T;F@Œ[
U:RDoc::Constant[i I"VERSION;FI"CSV::VERSION;T00o;;[o; ;[I"*The version of the installed library.;T;@‡;0@‡@cRDoc::NormalClass0U;[i I"FieldInfo;FI"CSV::FieldInfo;T00o;;[o; ;[ I"NA FieldInfo Struct contains details about a field's position in the data ;TI"Rsource it was read from. CSV will pass this Struct to some blocks that make ;TI"Jdecisions based on field structure. See CSV.convert_fields() for an ;TI"
example.;T@o:RDoc::Markup::List:
@type: NOTE:@items[o:RDoc::Markup::ListItem:@label[I"index;T;[o; ;[I"2The zero-based index of the field in its row.;To;;[I"line;T;[o; ;[I"2The line of the data source this row is from.;To;;[I"header;T;[o; ;[I"/The header for the column, when available.;T;@‡;0@‡@@©0U;[i I"DateMatcher;FI"CSV::DateMatcher;T00o;;[o; ;[I"@A Regexp used to find and convert some common Date formats.;T;@‡;0@‡@@©0U;[i I"DateTimeMatcher;FI"CSV::DateTimeMatcher;T00o;;[o; ;[I"DA Regexp used to find and convert some common DateTime formats.;T;@‡;0@‡@@©0U;[i I"ConverterEncoding;FI"CSV::ConverterEncoding;T00o;;[o; ;[I")The encoding used by all converters.;T;@‡;0@‡@@©0U;[i I"Converters;FI"CSV::Converters;T00o;;[
o; ;[I"RThis Hash holds the built-in converters of CSV that can be accessed by name. ;TI"PYou can select Converters with CSV.convert() or through the +options+ Hash ;TI"passed to CSV::new().;T@o;;;;[o;;[I":integer;T;[o; ;[I"*Converts any field Integer() accepts.;To;;[I":float;T;[o; ;[I"(Converts any field Float() accepts.;To;;[I":numeric;T;[o; ;[I"(A combination of :integer ;TI"and :float.;To;;[I":date;T;[o; ;[I".Converts any field Date::parse() accepts.;To;;[I":date_time;T;[o; ;[I"2Converts any field DateTime::parse() accepts.;To;;[I":all;T;[o; ;[I"0All built-in converters. A combination of ;TI"/:date_time and :numeric.;T@o; ;[I"OAll built-in converters transcode field data to UTF-8 before attempting a ;TI"Qconversion. If your data cannot be transcoded to UTF-8 the conversion will ;TI".fail and the field will remain unchanged.;T@o; ;[I"PThis Hash is intentionally left unfrozen and users should feel free to add ;TI":values to it that can be accessed by all CSV objects.;T@o; ;[I"PTo add a combo field, the value should be an Array of names. Combo fields ;TI"+can be nested with other combo fields.;T;@‡;0@‡@@©0U;[i I"HeaderConverters;FI"CSV::HeaderConverters;T00o;;[
o; ;[I"PThis Hash holds the built-in header converters of CSV that can be accessed ;TI"Lby name. You can select HeaderConverters with CSV.header_convert() or ;TI"5through the +options+ Hash passed to CSV::new().;T@o;;;;[o;;[I":downcase;T;[o; ;[I"+Calls downcase() on the header String.;To;;[I":symbol;T;[o; ;[ I"4Leading/trailing spaces are dropped, string is ;TI"3downcased, remaining spaces are replaced with ;TI"3underscores, non-word characters are dropped, ;TI"$and finally to_sym() is called.;T@o; ;[I"JAll built-in header converters transcode header data to UTF-8 before ;TI"Nattempting a conversion. If your data cannot be transcoded to UTF-8 the ;TI"?conversion will fail and the header will remain unchanged.;T@o; ;[I"PThis Hash is intentionally left unfrozen and users should feel free to add ;TI":values to it that can be accessed by all CSV objects.;T@o; ;[I"PTo add a combo field, the value should be an Array of names. Combo fields ;TI"+can be nested with other combo fields.;T;@‡;0@‡@@©0U;[i I"DEFAULT_OPTIONS;FI"CSV::DEFAULT_OPTIONS;T00o;;[o; ;[I"MThe options used when no overrides are given by calling code. They are:;T@o;;;;[o;;[I":col_sep;T;[o; ;[I"",";To;;[I":row_sep;T;[o; ;[I":auto;To;;[I" :quote_char;T;[o; ;[I"'"';To;;[I"&:field_size_limit;T;[o; ;[I"
+nil+;To;;[I" :converters;T;[o; ;[I"
+nil+;To;;[I"(:unconverted_fields;T;[o; ;[I"
+nil+;To;;[I":headers;T;[o; ;[I"+false+;To;;[I"$:return_headers;T;[o; ;[I"+false+;To;;[I"':header_converters;T;[o; ;[I"
+nil+;To;;[I"!:skip_blanks;T;[o; ;[I"+false+;To;;[I"":force_quotes;T;[o; ;[I"+false+;To;;[I" :skip_lines;T;[o; ;[I"
+nil+;To;;[I"%:liberal_parsing;T;[o; ;[I"+false+;T;@‡;0@‡@@©0[[I"Enumerable;To;;[ ;@‡;0@Œ[[I"
class;T[[;[[I"filter;F@Œ[I"foreach;F@Œ[I"
generate;F@Œ[I"generate_line;F@Œ[I"
instance;F@Œ[I"new;T@Œ[I" open;F@Œ[I"
parse;F@Œ[I"parse_line;F@Œ[I" read;F@Œ[I"readlines;F@Œ[I"
table;F@Œ[:protected[ [:private[ [I"
instance;T[[;[[I"<<;T@Œ[I"add_row;T@Œ[I"convert;F@Œ[I"converters;F@Œ[I" each;F@Œ[I"force_quotes?;F@Œ[I" gets;T@Œ[I"header_convert;F@Œ[I"header_converters;F@Œ[I"header_row?;F@Œ[I"headers;F@Œ[I"inspect;F@Œ[I"liberal_parsing?;F@Œ[I" puts;T@Œ[I" read;F@Œ[I"
readline;T@Œ[I"readlines;T@Œ[I"return_headers?;F@Œ[I"rewind;F@Œ[I"
shift;F@Œ[I"skip_blanks?;F@Œ[I"unconverted_fields?;F@Œ[I"write_headers?;F@Œ[;[ [;[[I"add_converter;F@Œ[I"add_unconverted_fields;F@Œ[I"convert_fields;F@Œ[I"encode_re;F@Œ[I"encode_str;F@Œ[I"escape_re;F@Œ[I"init_comments;F@Œ[I"init_converters;F@Œ[I"init_headers;F@Œ[I"init_parsers;F@Œ[I"init_separators;F@Œ[I"parse_headers;F@Œ[I"raw_encoding;F@Œ[[I"Forwardable;To;;[o; ;[I"#IO and StringIO Delegation ###;T;@‡;0@Œ[U:RDoc::Context::Section[i 0o;;[ ;0;0[@‡@‡cRDoc::TopLevel