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

class CSV::Table

クラスの継承リスト: CSV::Table < Enumerable < Object < Kernel < BasicObject
extend: Forwardable

要約

CSV::Table は CSV ドキュメントを表す二次元のデータ構造です。 行単位や列単位の操作を行うことが出来ます。また必要であれば CSV に 戻すこともできます。

ヘッダ行の処理が有効である場合、CSV から返されるテーブルは全てこのクラスから 構築されます。

以下のメソッドを Array に委譲します。

* empty?() * length() * size()

特異メソッド

定義 説明
new(array_of_rows) -> CSV::Table

自身を初期化します。

インスタンスメソッド

定義 説明
self << row_or_array -> self

自身の最後に新しい行を追加します。

self == other -> bool

自身の全ての行が比較対象と同じである場合は真を返します。 そうでない場合は偽を返します。

self[index_or_header] -> object

In the default mixed mode, this method returns rows for index access and columns for header access. You can force the index association by first calling by_col!() or by_row!().

self[index_or_header] = value

In the default mixed mode, this method assigns rows for index access and columns for header access. You can force the index association by first calling by_col!() or by_row!().

by_col -> CSV::Table

カラムモードになっている新しい CSV::Table オブジェクトを返します。

by_col! -> self

自身をカラムモードに変更します。

by_col_or_row -> CSV::Table

ミックスモードになっている新しい CSV::Table オブジェクトを返します。

by_col_or_row! -> self

自身をミックスモードに変更します。

by_row -> CSV::Table

Returns a duplicate table object, in row mode. This is handy for chaining in a single call without changing the table mode, but be aware that this method can consume a fair amount of memory for bigger data sets.

by_row! -> self

Switches the mode of this table to row mode. All calls to indexing and iteration methods will work with rows until the mode is changed again.

delete(index_or_header) -> Object

Removes and returns the indicated column or row. In the default mixed mode indices refer to rows and everything else is assumed to be a column header. Use by_col!() or by_row!() to force the lookup.

delete_if { ... } -> self

Removes any column or row for which the block returns +true+. In the default mixed mode or row mode, iteration is the standard row major walking of rows. In column mode, interation will +yield+ two element tuples containing the column name and an Array of values for that column.

each {|header, field| ... } -> self

In the default mixed mode or row mode, iteration is the standard row major walking of rows. In column mode, interation will +yield+ two element tuples containing the column name and an Array of values for that column.

empty? -> bool

delegate

headers -> Array

Returns the headers for the first row of this table (assumed to match all other rows). An empty Array is returned for empty tables.

inspect -> String

Shows the mode and size of this table in a US-ASCII String.

length -> Fixnum
size -> Fixnum

delegate

mode -> Symbol

現在のアクセスモードを返します。

push(*rows) -> self

A shortcut for appending multiple rows. Equivalent to:

table -> Array

同値性を比較するために内部的に使用します。

to_a -> Array

Returns the table as an Array of Arrays. Headers will be the first row, then all of the field rows will follow.

to_csv -> String
to_s -> String

Returns the table as a complete CSV String. Headers will be listed first, then all of the field rows.

values_at(indices_or_headers) -> Array

The mixed mode default is to treat a list of indices as row access, returning the rows indicated. Anything else is considered columnar access. For columnar access, the return set has an Array for each row with the values indicated by the headers in each Array. You can force column or row mode using by_col!() or by_row!().

継承したメソッド

! != all? any? chunk collect collect_concat count cycle detect drop drop_while each_cons each_entry each_slice each_with_index each_with_object entries find_all find_index first grep group_by include? inject max max_by min min_by minmax minmax_by none? one? partition reject reverse_each slice_before sort sort_by take take_while to_set zip def_delegator def_delegators === =~ __id__ __send__ _dump class clone dclone display enum_for eql? equal? extend freeze frozen? hash initialize initialize_copy 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 must_be must_be_close_to must_be_empty must_be_instance_of must_be_kind_of must_be_nil must_be_same_as must_be_within_epsilon must_equal must_include must_match must_raise must_respond_to must_send must_throw 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? respond_to_missing? singleton_class singleton_method_added singleton_method_removed singleton_method_undefined singleton_methods taint tainted? tap to_ary to_hash to_int to_io to_proc to_regexp to_str to_yaml to_yaml_properties to_yaml_style trust untaint untrust untrusted? wont_be wont_be_close_to wont_be_empty wont_be_instance_of wont_be_kind_of wont_be_nil wont_be_same_as wont_be_within_epsilon wont_equal wont_include wont_match wont_respond_to