Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > csvライブラリ > CSVクラス

class CSV

クラスの継承リスト: CSV < Object < Kernel

要約

CSV (Comma Separated Values) を扱うクラスです。

各メソッドの共通パラメタ

mode
   'r', 'w', 'rb', 'wb' から指定可能です。

   - 'r' 読み込み
   - 'w' 書き込み
   - 'b' バイナリモード
fs
   フィールドの区切り文字
   デフォルトは ','
rs
   行区切り文字。nil (デフォルト) で CrLf / Lf。
   Cr で区切りたい場合は ?\r を渡します。

特異メソッド

定義 説明
foreach(path, rs = nil) {|row| ... } -> nil

読み込みモードでファイルを開き、各行を配列でブロックに渡します。

generate(path, fs = nil, rs = nil) -> CSV::BasicWriter
generate(path, fs = nil, rs = nil) {|writer| ... } -> nil

path で指定されたファイルを書き込みモードで開き、ブロックに渡します。 ブロック未指定の場合は CSV::BasicWriter を返します。

generate_line(row, fs = nil, rs = nil) -> String
generate_line(row, fs = nil, rs = nil) {|s| ... } -> nil

row で指定された配列をパースし、fs で指定された文字をフィールドセパレータとして 1行分の文字列をブロックに渡します。 ブロック未指定の場合は変換された文字列を返します。

generate_row(src, cells, out_dev, fs = nil, rs = nil) -> Fixnum

src で指定された配列をパースして csv形式の文字列として(行区切り文字も含めて) out_dev に出力します。 返り値として fs で区切ったフィールド(cell)の数を返します。

open(path, mode, fs = nil, rs = nil) {|row| ... } -> nil
open(path, mode, fs = nil, rs = nil) -> CSV::Reader | CSV::Writer

CSVファイルを読み込んでパースします。

parse(str_or_readable, fs = nil, rs = nil) -> Array
parse(str_or_readable, fs = nil, rs = nil) {|rows| ... } -> nil

str_or_readable で指定された文字列をパースし配列の配列に変換、ブロックに渡します。 ブロック未指定の場合は変換された配列の配列を返します。

parse_line(src, fs = nil, rs = nil) -> Array
parse_line(src, fs = nil, rs = nil) {|row| ... } -> nil

src で指定された文字列を1行分としてパースし配列に変換、ブロックに渡します。 ブロック未指定の場合は変換された配列を返します。

parse_row(src, index, out_dev, fs = nil, rs = nil) -> Array

CSV形式の文字列をパースしてCSV1行(row)分のデータを配列に変換し out_dev に出力します。

read(path, length = nil, offset = nil) -> Array

path で指定された CSV ファイルを読み込み、配列の配列でデータを返します。

readlines(path, rs = nil) -> Array

path で指定された CSV ファイルを読み込み、配列の配列でデータを返します。

継承したメソッド

== === =~ __id__ __send__ _dump class clone dclone display enum_for eql? equal? extend freeze frozen? hash initialize initialize_copy inspect instance_eval instance_exec instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? marshal_dump marshal_load method method_missing methods nil? pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods protected_methods public_methods remove_instance_variable respond_to? singleton_method_added singleton_method_removed singleton_method_undefined singleton_methods taint tainted? tap to_a to_ary to_hash to_int to_io to_proc to_regexp to_s to_str to_yaml to_yaml_properties to_yaml_style untaint .new