Linux heracles.o2switch.net 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
/
opt
/
alt
/
ruby27
/
share
/
ri
/
system
/
CSV
/
//opt/alt/ruby27/share/ri/system/CSV/cdesc-CSV.ri
U:RDoc::NormalClass[iI"CSV:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[6o:RDoc::Markup::Paragraph;[I"OThis 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 o; ;[I"2The most generic interface of the library is:;T@o:RDoc::Markup::Verbatim;[I",csv = CSV.new(string_or_io, **options) ;TI" ;TI"2# Reading: IO object should be open for read ;TI"!csv.read # => array of rows ;TI" # or ;TI"csv.each do |row| ;TI" # ... ;TI" end ;TI" # or ;TI"row = csv.shift ;TI" ;TI"3# Writing: IO object should be open for write ;TI"csv << row ;T:@format0o; ;[I"WThere are several specialized class methods for one-statement reading or writing, ;TI"2described in the Specialized Methods section.;T@o; ;[I"WIf a String is passed into ::new, it is internally wrapped into a StringIO object.;T@o; ;[I"L+options+ can be used for specifying the particular CSV flavor (column ;TI"Tseparators, row separators, value quoting and so on), and for data conversion, ;TI"Csee Data Conversion section for the description of the latter.;T@S:RDoc::Markup::Heading: leveli: textI"Specialized Methods;T@S; ;i;I"Reading;T@o;;[I" # From a file: all at once ;TI";arr_of_rows = CSV.read("path/to/file.csv", **options) ;TI"# iterator-style: ;TI"9CSV.foreach("path/to/file.csv", **options) do |row| ;TI" # ... ;TI" end ;TI" ;TI"# From a string ;TI";arr_of_rows = CSV.parse("CSV,data,String", **options) ;TI" # or ;TI"6CSV.parse("CSV,data,String", **options) do |row| ;TI" # ... ;TI" end ;T;0S; ;i;I"Writing;T@o;;[I"# To a file ;TI"1CSV.open("path/to/file.csv", "wb") do |csv| ;TI"+ csv << ["row", "of", "CSV", "data"] ;TI"! csv << ["another", "row"] ;TI" # ... ;TI" end ;TI" ;TI"# To a String ;TI"(csv_string = CSV.generate do |csv| ;TI"+ csv << ["row", "of", "CSV", "data"] ;TI"! csv << ["another", "row"] ;TI" # ... ;TI" end ;T;0S; ;i;I"Shortcuts;T@o;;[I"/# Core extensions for converting one line ;TI"4csv_string = ["CSV", "data"].to_csv # to CSV ;TI"6csv_array = "CSV,String".parse_csv # from CSV ;TI" ;TI"# CSV() method ;TI"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"Data Conversion;T@S; ;i;I"CSV with headers;T@o; ;[I"RCSV allows to specify column names of CSV file, whether they are in data, or ;TI"Wprovided separately. If headers are specified, reading methods return an instance ;TI"+of CSV::Table, consisting of CSV::Row.;T@o;;[I" # Headers are part of data ;TI".data = CSV.parse(<<~ROWS, headers: true) ;TI" Name,Department,Salary ;TI" Bob,Engineering,1000 ;TI" Jane,Sales,2000 ;TI" John,Management,5000 ;TI" ROWS ;TI" ;TI"$data.class #=> CSV::Table ;TI"]data.first #=> #<CSV::Row "Name":"Bob" "Department":"Engineering" "Salary":"1000"> ;TI"Xdata.first.to_h #=> {"Name"=>"Bob", "Department"=>"Engineering", "Salary"=>"1000"} ;TI" ;TI"%# Headers provided by developer ;TI"Sdata = CSV.parse('Bob,Engineering,1000', headers: %i[name department salary]) ;TI"Wdata.first #=> #<CSV::Row name:"Bob" department:"Engineering" salary:"1000"> ;T;0S; ;i;I"Typed data reading;T@o; ;[I"[CSV allows to provide a set of data _converters_ e.g. transformations to try on input ;TI"Wdata. Converter could be a symbol from CSV::Converters constant's keys, or lambda.;T@o;;[I"# Without any converters: ;TI"%CSV.parse('Bob,2018-03-01,100') ;TI"(#=> [["Bob", "2018-03-01", "100"]] ;TI" ;TI"!# With built-in converters: ;TI"CCSV.parse('Bob,2018-03-01,100', converters: %i[numeric date]) ;TI"-#=> [["Bob", #<Date: 2018-03-01>, 100]] ;TI" ;TI"# With custom converters: ;TI"UCSV.parse('Bob,2018-03-01,100', converters: [->(v) { Time.parse(v) rescue v }]) ;TI"5#=> [["Bob", 2018-03-01 00:00:00 +0200, "100"]] ;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"Sor 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"Rthe Encoding it is in. Thus CSV will return Arrays or Rows of Strings in the ;TI"REncoding 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"Esupport. For example, <tt>:col_sep</tt>, <tt>:row_sep</tt>, and ;TI"Q<tt>:quote_char</tt> must be transcoded to match your data. Hopefully this ;TI"Qmakes the entire process feel transparent, since CSV's defaults should just ;TI"Qmagically 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"IEncoding 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"Iavoid this translation. It's just too hard for me to support native ;TI",conversions in all of Ruby's Encodings.;T@o; ;[ I"SAnyway, 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"Nthat 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"REncoding 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"LRuby 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_below0o;;[ ;I"lib/csv/delete_suffix.rb;T;0o;;[ ;I" lib/csv/fields_converter.rb;T;0o;;[ ;I"lib/csv/match_p.rb;T;0o;;[ ;I"lib/csv/parser.rb;T;0o;;[ ;I"lib/csv/row.rb;T;0o;;[ ;I"lib/csv/table.rb;T;0o;;[ ;I"lib/csv/version.rb;T;0o;;[ ;I"lib/csv/writer.rb;T;0;0;0[[ I" encoding;TI"R;T:privateFI"lib/csv.rb;T[ U:RDoc::Constant[i I"FieldInfo;TI"CSV::FieldInfo;T:public0o;;[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"<b><tt>index</tt></b>;T;[o; ;[I"2The zero-based index of the field in its row.;To;;[I"<b><tt>line</tt></b>;T;[o; ;[I"2The line of the data source this row is from.;To;;[I"<b><tt>header</tt></b>;T;[o; ;[I"/The header for the column, when available.;T;@�;0@�@cRDoc::NormalClass0U;[i I"DateMatcher;TI"CSV::DateMatcher;T;0o;;[o; ;[I"@A Regexp used to find and convert some common Date formats.;T;@�;0@�@@�0U;[i I"DateTimeMatcher;TI"CSV::DateTimeMatcher;T;0o;;[o; ;[I"DA Regexp used to find and convert some common DateTime formats.;T;@�;0@�@@�0U;[i I"ConverterEncoding;TI"CSV::ConverterEncoding;T;0o;;[o; ;[I")The encoding used by all converters.;T;@�;0@�@@�0U;[i I"Converters;TI"CSV::Converters;T;0o;;[ 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"<b><tt>:integer</tt></b>;T;[o; ;[I"*Converts any field Integer() accepts.;To;;[I"<b><tt>:float</tt></b>;T;[o; ;[I"(Converts any field Float() accepts.;To;;[I"<b><tt>:numeric</tt></b>;T;[o; ;[I"(A combination of <tt>:integer</tt> ;TI"and <tt>:float</tt>.;To;;[I"<b><tt>:date</tt></b>;T;[o; ;[I".Converts any field Date::parse() accepts.;To;;[I"<b><tt>:date_time</tt></b>;T;[o; ;[I"2Converts any field DateTime::parse() accepts.;To;;[I"<b><tt>:all</tt></b>;T;[o; ;[I"0All built-in converters. A combination of ;TI"/<tt>:date_time</tt> and <tt>:numeric</tt>.;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;TI"CSV::HeaderConverters;T;0o;;[ o; ;[I"PThis Hash holds the built-in header converters of CSV that can be accessed ;TI"Kby name. You can select HeaderConverters with CSV.header_convert() or ;TI"5through the +options+ Hash passed to CSV::new().;T@o;;;;[o;;[I"<b><tt>:downcase</tt></b>;T;[o; ;[I"+Calls downcase() on the header String.;To;;[I"<b><tt>:symbol</tt></b>;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"Mattempting 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"OTo 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;TI"CSV::DEFAULT_OPTIONS;T;0o;;[o; ;[I"LThe options used when no overrides are given by calling code. They are:;T@o;;;;[o;;[I"<b><tt>:col_sep</tt></b>;T;[o; ;[I"<tt>","</tt>;To;;[I"<b><tt>:row_sep</tt></b>;T;[o; ;[I"<tt>:auto</tt>;To;;[I" <b><tt>:quote_char</tt></b>;T;[o; ;[I"<tt>'"'</tt>;To;;[I"&<b><tt>:field_size_limit</tt></b>;T;[o; ;[I" +nil+;To;;[I" <b><tt>:converters</tt></b>;T;[o; ;[I" +nil+;To;;[I"(<b><tt>:unconverted_fields</tt></b>;T;[o; ;[I" +nil+;To;;[I"<b><tt>:headers</tt></b>;T;[o; ;[I"+false+;To;;[I"$<b><tt>:return_headers</tt></b>;T;[o; ;[I"+false+;To;;[I"'<b><tt>:header_converters</tt></b>;T;[o; ;[I" +nil+;To;;[I"!<b><tt>:skip_blanks</tt></b>;T;[o; ;[I"+false+;To;;[I""<b><tt>:force_quotes</tt></b>;T;[o; ;[I"+false+;To;;[I" <b><tt>:skip_lines</tt></b>;T;[o; ;[I" +nil+;To;;[I"%<b><tt>:liberal_parsing</tt></b>;T;[o; ;[I"+false+;To;;[I"!<b><tt>:quote_empty</tt></b>;T;[o; ;[I"+true+;T;@�;0@�@@�0U;[i I"VERSION;TI"CSV::VERSION;T;0o;;[o; ;[I"*The version of the installed library.;T;@�;0@�@@�0[[I"Enumerable;To;;[ ;@�;0@�[[I" class;T[[;[ [:protected[ [;[[I"filter;T@�[I"foreach;T@�[I" generate;T@�[I"generate_line;T@�[I" instance;T@�[I"new;T@�[I" open;T@�[I" parse;T@�[I"parse_line;T@�[I" read;T@�[I"readlines;T@�[I" table;T@�[I" instance;T[[;[ [;[ [;[<[I"<<;T@�[I"add_row;T@�[I" binmode?;T@�[I"build_fields_converter;T@�[I""build_header_fields_converter;T@�[I""build_parser_fields_converter;T@�[I""build_writer_fields_converter;T@�[I"col_sep;T@�[I"convert;T@�[I"convert_fields;T@�[I"converters;T@�[I"determine_encoding;T@�[I" each;T@�[I"eof;T@�[I" eof?;T@�[I"field_size_limit;T@�[I" flock;T@�[I"force_quotes?;T@�[I" gets;T@�[I"header_convert;T@�[I"header_converters;T@�[I"header_fields_converter;T@�[I"header_row?;T@�[I"headers;T@�[I"inspect;T@�[I" ioctl;T@�[I"liberal_parsing?;T@�[I" line;T@�[I"lineno;T@�[I"normalize_converters;T@�[I"parser;T@�[I"parser_enumerator;T@�[I"parser_fields_converter;T@�[I"parser_options;T@�[I" path;T@�[I" puts;T@�[I"quote_char;T@�[I"raw_encoding;T@�[I" read;T@�[I" readline;T@�[I"readlines;T@�[I"return_headers?;T@�[I"rewind;T@�[I"row_sep;T@�[I" shift;T@�[I"skip_blanks?;T@�[I"skip_lines;T@�[I" stat;T@�[I" to_i;T@�[I" to_io;T@�[I"unconverted_fields?;T@�[I"write_headers?;T@�[I"writer;T@�[I"writer_fields_converter;T@�[I"writer_options;T@�[[I"Forwardable;To;;[o; ;[I"#IO and StringIO Delegation ###;T;@�;0@�[U:RDoc::Context::Section[i 0o;;[ ;0;0[I"lib/csv.rb;TI"lib/csv/delete_suffix.rb;TI" lib/csv/fields_converter.rb;TI"lib/csv/match_p.rb;TI"lib/csv/parser.rb;TI"lib/csv/row.rb;TI"lib/csv/table.rb;TI"lib/csv/version.rb;TI"lib/csv/writer.rb;T@�cRDoc::TopLevel