るりまサーチ

最速Rubyリファレンスマニュアル検索!
72件ヒット [1-72件を表示] (0.133秒)
トップページ > クエリ:t[x] > クエリ:Ruby[x] > 種類:インスタンスメソッド[x] > クエリ:r[x] > クエリ:ruby[x] > クエリ:self[x] > ライブラリ:csv[x] > クラス:CSV::Table[x]

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

キーワード

検索結果

CSV::Table#by_col_or_row! -> self (9217.0)

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

...@return 必ず自身を返すので安全にメソッドチェーンできます。

//emlist[例][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
r
ow2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
t
able = CSV::Table.new([row1, row2]).by_col!
t
a...
...ble # => #<CSV::Table mode:col row_count:3>
t
able.by_col_or_row!
t
able # => #<CSV::Table mode:col_or_row row_count:3>
//}...

CSV::Table#by_row! -> self (9217.0)

自身をロウモードに変更します。

...@return 必ず自身を返すので安全にメソッドチェーンできます。

//emlist[例][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
r
ow2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
t
able = CSV::Table.new([row1, row2])
t
able...
...# => #<CSV::Table mode:col_or_row row_count:3>
t
able.by_row!
t
able # => #<CSV::Table mode:row row_count:3>
t
able[0] # => #<CSV::Row "header1":"row1_1" "header2":"row1_2">
t
able[1] # => #<CSV::Row "header1":"row2_1" "header2":"row2_2">
//}...

CSV::Table#delete_if {|row| ... } -> self (6330.0)

ブロックを評価した結果が真である行か列を削除します。

...ist[例 ロウモード][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1", "header2"], ["row1_1", "valid"])
r
ow2 = CSV::Row.new(["header1", "header2"], ["row2_1", "invalid"])
r
ow3 = CSV::Row.new(["header1", "header2"], ["row3_1", "valid"])
t
able = CSV::Table.new([row1, row2, row3])
t
able.delete_...
...{ |row| row["header2"] == "invalid" }
t
able.to_a # => [["header1", "header2"], ["row1_1", "valid"], ["row3_1", "valid"]]
//}

//emlist[例 カラムモード][ruby]{
r
equire "csv"
r
ow1 = CSV::Row.new(["id", "name"], [1, "tanaka"])
r
ow2 = CSV::Row.new(["id", "name"], [2, "suzuki"])
r
ow3 = CSV::Row.n...
...ew(["id", "name"], [3, "sato"])
t
able = CSV::Table.new([row1, row2, row3])
t
able.by_col!
t
able.delete_if { |column_name, values| column_name == "id" }
t
able.to_a # => [["name"], ["tanaka"], ["suzuki"], ["sato"]]
//}

@see CSV::Table#delete...

CSV::Table#push(*rows) -> self (3235.0)

複数の行を追加するためのショートカットです。

...ist[][ruby]{
r
ows.each {|row| self << row }
//}

@param rows CSV::Row のインスタンスか配列を指定します。

//emlist[例][ruby]{
r
equire 'csv'
csv
= CSV.new("a,b,c\n1,2,3", headers: true)
t
able = csv.read
r
ows = [
CSV
::Row.new(table.headers, [4, 5, 6]),
[7, 8, 9]
]

t
able.push(*ro...
...ws)
p table[0..2]
# => [#<CSV::Row "a":"1" "b":"2" "c":"3">, #<CSV::Row "a":4 "b":5 "c":6>, #<CSV::Row "a":7 "b":8 "c":9>]
//}

@see CSV::Table#<<...

CSV::Table#each {|row| ... } -> self (3230.0)

デフォルトのミックスモードかロウモードでは、行単位で繰り返します。カラ ムモードでは、ブロックに列名と対応する値の配列を与え、列単位で繰り返し ます。

...//emlist[例 ロウモード][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
r
ow2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
r
ow3 = CSV::Row.new(["header1", "header2"], ["row3_1", "row3_2"])
t
able = CSV::Table.new([row1, row2, row3])
t
able.e...
...|row| p row }

# => #<CSV::Row "header1":"row1_1" "header2":"row1_2">
# => #<CSV::Row "header1":"row2_1" "header2":"row2_2">
# => #<CSV::Row "header1":"row3_1" "header2":"row3_2">
//}

//emlist[例 カラムモード][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row...
..."])
r
ow2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
r
ow3 = CSV::Row.new(["header1", "header2"], ["row3_1", "row3_2"])
t
able = CSV::Table.new([row1, row2, row3])
t
able.by_col!
t
able.each { |column_name, values| print column_name, values, "\n" }

# => header1["row1_1", "row2_1", "row...

絞り込み条件を変える

CSV::Table#<<(row_or_array) -> self (3217.0)

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

...aram row_or_array CSV::Row のインスタンスか配列を指定します。
配列を指定した場合は CSV::Row に変換されます。

@return メソッドチェーンのために自身を返します。

//emlist[例][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1...
...", "header2"], ["row1_1", "row1_2"])
r
ow2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
t
able = CSV::Table.new([row1])
t
able << row2
t
able.to_a # => [["header1", "header2"], ["row1_1", "row1_2"], ["row2_1", "row2_2"]]
//}...