33件ヒット
[1-33件を表示]
(0.027秒)
検索結果
先頭3件
-
CSV (38406.0)
-
このクラスは CSV ファイルやデータに対する完全なインターフェイスを提供します。
...は CSV ファイルやデータに対する完全なインターフェイスを提供します。
=== 読み込み
//emlist[][ruby]{
require "csv"
csv_text = <<~CSV_TEXT
Ruby,1995
Rust,2010
CSV_TEXT
IO.write "sample.csv", csv_text
# ファイルから一行ずつ
CSV.foreach("sample.csv")......書き込み
csv_string = CSV.generate do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ...
end
//}
=== 一行変換
//emlist[][ruby]{
require 'csv'
csv_string = ["CSV", "data"].to_csv # => "CSV,data"
csv_array = "CSV,String".parse_csv # => ["CSV", "String"]
//}......omes when generating CSV into a String with an Encoding
that is not ASCII compatible. There's no existing data for CSV to use to
prepare itself and thus you will probably need to manually specify the desired
Encoding for most of those cases. It will try to guess using the fields in a
row of output... -
CSV
:: Row # fields(*headers _ and _ or _ indices) -> Array (21233.0) -
与えられた引数に対応する値の配列を返します。
...与えられた引数に対応する値の配列を返します。
要素の探索に CSV::Row.field を使用しています。
@param headers_and_or_indices ヘッダの名前かインデックスか Range
のインスタンスか第 1 要素がヘッダの名前......るこ
とができます。
@return 引数を与えなかった場合は全ての要素を返します。
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
row = table.first
row.values_at("a", 1, 2..3) # => ["1", "2", "3", nil]... -
CSV
:: Row # values _ at(*headers _ and _ or _ indices) -> Array (6133.0) -
与えられた引数に対応する値の配列を返します。
...与えられた引数に対応する値の配列を返します。
要素の探索に CSV::Row.field を使用しています。
@param headers_and_or_indices ヘッダの名前かインデックスか Range
のインスタンスか第 1 要素がヘッダの名前......るこ
とができます。
@return 引数を与えなかった場合は全ての要素を返します。
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
row = table.first
row.values_at("a", 1, 2..3) # => ["1", "2", "3", nil]...