別のキーワード
種類
- インスタンスメソッド (17)
- 特異メソッド (6)
ライブラリ
- csv (23)
キーワード
- binmode (1)
- binmode? (1)
- closed? (1)
- eof (1)
- eof? (1)
-
field
_ size _ limit (1) -
force
_ quotes? (1) -
header
_ row? (1) - instance (1)
- isatty (1)
- open (2)
- read (2)
- readlines (2)
-
return
_ headers? (1) -
skip
_ blanks? (1) - sync (1)
- table (1)
- tty? (1)
-
unconverted
_ fields? (1) -
write
_ headers? (1)
検索結果
先頭5件
-
CSV
. table(path , options = Hash . new) -> CSV :: Table | [Array] (18604.0) -
以下と同等のことを行うメソッドです。
...ッドです。
//emlist[][ruby]{
CSV.read( path, { headers: true,
converters: :numeric,
header_converters: :symbol }.merge(options) )
//}
@param path ファイル名を指定します。
@param options CSV.new のオプションと同じオプ......ションを指定できます。
@see CSV.read... -
CSV
# binmode -> self (18304.0) -
IO#binmode に委譲します。
IO#binmode に委譲します。
@see IO#binmode -
CSV
# binmode? -> bool (18304.0) -
IO#binmode? に委譲します。
IO#binmode? に委譲します。
@see IO#binmode? -
CSV
# skip _ blanks? -> bool (18304.0) -
真である場合は、空行を読み飛ばします。
...[例][ruby]{
require "csv"
csv = CSV.new("header1,header2\n\nrow1_1,row1_2")
csv.skip_blanks? # => false
csv.read # => [["header1", "header2"], [], ["row1_1", "row1_2"]]
csv = CSV.new("header1,header2\n\nrow1_1,row1_2", skip_blanks: true)
csv.skip_blanks? # => true
csv.read # => [["......header1", "header2"], ["row1_1", "row1_2"]]
//}
@see CSV.new... -
CSV
# closed? -> bool (304.0) -
IO#closed? に委譲します。
IO#closed? に委譲します。
@see IO#closed? -
CSV
# eof -> bool (304.0) -
IO#eof, IO#eof? に委譲します。
IO#eof, IO#eof? に委譲します。
@see IO#eof, IO#eof? -
CSV
# eof? -> bool (304.0) -
IO#eof, IO#eof? に委譲します。
IO#eof, IO#eof? に委譲します。
@see IO#eof, IO#eof? -
CSV
# force _ quotes? -> bool (304.0) -
出力される全てのフィールドがクオートされる場合は、真を返します。
...]{
require "csv"
rows = [["header1", "header2"], ["row1_1,", "row1_2"]]
result = CSV.generate(force_quotes: false) do |csv|
rows.each { |row| csv << row }
csv.force_quotes? # => false
end
print result
# => header1,header2
# "row1_1,",row1_2
//}
//emlist[例][ruby]{
require "csv"
rows = [[......"header1", "header2"], ["row1_1,", "row1_2"]]
result = CSV.generate(force_quotes: true) do |csv|
rows.each { |row| csv << row }
csv.force_quotes? # => true
end
print result
# => true
# => "header1","header2"
# "row1_1,","row1_2"
//}
@see CSV.new... -
CSV
# header _ row? -> bool (304.0) -
次に読み込まれる行が、ヘッダである場合に真を返します。 そうでない場合は、偽を返します。
...に読み込まれる行が、ヘッダである場合に真を返します。
そうでない場合は、偽を返します。
//emlist[例][ruby]{
require "csv"
csv = CSV.new("header1,header2\nrow1_1,row1_2", headers: true)
csv.header_row? # => true
csv.readline
csv.header_row? # => false
//}... -
CSV
# isatty -> bool (304.0) -
IO#isatty, IO#tty? に委譲します。
IO#isatty, IO#tty? に委譲します。
@see IO#isatty, IO#tty? -
CSV
# read -> [Array] | CSV :: Table (304.0) -
残りの行を読み込んで配列の配列を返します。 self の生成時に headers オプションに偽でない値が指定されていた場合は CSV::Table オブジェクトを返します。
...い値が指定されていた場合は CSV::Table オブジェクトを返します。
データソースは読み込み用にオープンされている必要があります。
//emlist[例 headers: false][ruby]{
require "csv"
csv = CSV.new(DATA.read)
csv.read
# => [["header1", "header2"], ["ro......_1", "row1_2"], ["row2_1", "row2_2"]]
__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}
//emlist[例 headers: true][ruby]{
require "csv"
csv = CSV.new(DATA.read, headers: true)
csv.read
# => #<CSV::Table mode:col_or_row row_count:3>
__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}... -
CSV
# readlines -> [Array] | CSV :: Table (304.0) -
残りの行を読み込んで配列の配列を返します。 self の生成時に headers オプションに偽でない値が指定されていた場合は CSV::Table オブジェクトを返します。
...い値が指定されていた場合は CSV::Table オブジェクトを返します。
データソースは読み込み用にオープンされている必要があります。
//emlist[例 headers: false][ruby]{
require "csv"
csv = CSV.new(DATA.read)
csv.read
# => [["header1", "header2"], ["ro......_1", "row1_2"], ["row2_1", "row2_2"]]
__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}
//emlist[例 headers: true][ruby]{
require "csv"
csv = CSV.new(DATA.read, headers: true)
csv.read
# => #<CSV::Table mode:col_or_row row_count:3>
__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}... -
CSV
# return _ headers? -> bool (304.0) -
ヘッダを返す場合は、真を返します。 そうでない場合は、偽を返します。
...]{
require "csv"
csv = CSV.new("header1,header2\nrow1_1,row1_2", headers: true, return_headers: false)
csv.return_headers? # => false
csv.shift # => #<CSV::Row "header1":"row1_1" "header2":"row1_2">
csv = CSV.new("header1,header2\nrow1_1,row1_2", headers: true, return_headers: true)
csv.return_hea......ders? # => true
csv.shift # => #<CSV::Row "header1":"header1" "header2":"header2">
//}
@see CSV.new... -
CSV
# sync -> bool (304.0) -
IO#sync に委譲します。
IO#sync に委譲します。
@see IO#sync -
CSV
# tty? -> bool (304.0) -
IO#isatty, IO#tty? に委譲します。
IO#isatty, IO#tty? に委譲します。
@see IO#isatty, IO#tty? -
CSV
# unconverted _ fields? -> bool (304.0) -
パースした結果が unconverted_fields というメソッドを持つ場合に真を返します。 そうでない場合は、偽を返します。
...ます。
//emlist[例][ruby]{
require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10")
csv.unconverted_fields? # => nil
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10", unconverted_fields: false)
csv.unconverted_fields? # => false
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10", h......_fields: true)
csv.unconverted_fields? # => true
csv.convert(:date)
row = csv.readline
row.fields # => [#<Date: 2018-07-09 ((2458309j,0s,0n),+0s,2299161j)>, #<Date: 2018-07-10 ((2458310j,0s,0n),+0s,2299161j)>]
row.unconverted_fields # => ["2018-07-09", "2018-07-10"]
//}
@see CSV.new... -
CSV
# write _ headers? -> bool (304.0) -
ヘッダを出力先に書き込む場合は真を返します。 そうでない場合は偽を返します。
...st[例][ruby]{
require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10")
csv.write_headers? # => nil
header = ["header1", "header2"]
row = ["row1_1", "row1_2"]
result = CSV.generate(headers: header, write_headers: false) do |csv|
csv.write_headers? # => false
csv << row
end
result # =>......"row1_1,row1_2\n"
result = CSV.generate(headers: header, write_headers: true) do |csv|
csv.write_headers? # => true
csv << row
end
result # => "header1,header2\nrow1_1,row1_2\n"
//}
@see CSV.new... -
CSV
. instance(data = $ stdout , options = Hash . new) {|csv| . . . } -> object (304.0) -
このメソッドは CSV.new のように CSV のインスタンスを返します。 しかし、返される値は Object#object_id と与えられたオプションを キーとしてキャッシュされます。
...このメソッドは CSV.new のように CSV のインスタンスを返します。
しかし、返される値は Object#object_id と与えられたオプションを
キーとしてキャッシュされます。
ブロックが与えられた場合、生成されたインスタンスをブ......ns CSV.new のオプションと同じオプションを指定できます。
//emlist[例][ruby]{
require "csv"
options = { headers: true }
text =<<-EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS
csv = CSV.instance(text, options)
csv2 = CSV.......instance(text, options)
csv.object_id == csv2.object_id # => true
print csv.read
# => id,first name,last name,age
# 1,taro,tanaka,20
# 2,jiro,suzuki,18
# 3,ami,sato,19
# 4,yumi,adachi,21
//}
@see CSV.new... -
CSV
. open(filename , mode = "rb" , options = Hash . new) -> CSV (304.0) -
このメソッドは IO オブジェクトをオープンして CSV でラップします。 これは CSV ファイルを書くための主要なインターフェイスとして使うことを意図しています。
...ンして CSV でラップします。
これは CSV ファイルを書くための主要なインターフェイスとして使うことを意図しています。
このメソッドは IO.open と同じように動きます。ブロックが与えられた場合は
ブロックに CSV オブジ......た場合は CSV オブジェクトを返します。
データが Encoding.default_external と異なる場合は、mode にエンコー
ディングを指定する文字列を埋め込まなければなりません。データをどのよう
に解析するか決定するために CSV ライブ......UTF-8 に変換してから解析します。
また "rb:BOM|UTF-8" のように mode を指定すると BOM を自動的に取り除きま
す。
CSV オブジェクトは多くのメソッドを IO や File に委譲します。
* IO#binmode
* IO#binmode?
* IO#close
* IO#close_read
*... -
CSV
. open(filename , mode = "rb" , options = Hash . new) {|csv| . . . } -> nil (304.0) -
このメソッドは IO オブジェクトをオープンして CSV でラップします。 これは CSV ファイルを書くための主要なインターフェイスとして使うことを意図しています。
...ンして CSV でラップします。
これは CSV ファイルを書くための主要なインターフェイスとして使うことを意図しています。
このメソッドは IO.open と同じように動きます。ブロックが与えられた場合は
ブロックに CSV オブジ......た場合は CSV オブジェクトを返します。
データが Encoding.default_external と異なる場合は、mode にエンコー
ディングを指定する文字列を埋め込まなければなりません。データをどのよう
に解析するか決定するために CSV ライブ......UTF-8 に変換してから解析します。
また "rb:BOM|UTF-8" のように mode を指定すると BOM を自動的に取り除きま
す。
CSV オブジェクトは多くのメソッドを IO や File に委譲します。
* IO#binmode
* IO#binmode?
* IO#close
* IO#close_read
*... -
CSV
. read(path , options = Hash . new) -> [Array] | CSV :: Table (304.0) -
CSV ファイルを配列の配列にするために使います。 headers オプションに偽でない値を指定した場合は CSV::Table オブジェクトを返します。
...
CSV ファイルを配列の配列にするために使います。
headers オプションに偽でない値を指定した場合は CSV::Table オブジェクトを返します。
@param path CSV ファイルのパスを指定します。
@param options CSV.new のオプションと同じオプ......しなければなりません。
//emlist[例][ruby]{
require "csv"
require "pp"
File.write("test.csv", <<CSV)
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
pp CSV.read("test.csv")
# => [["id", "first name", "last name", "age"],
# ["1", "tar....../}
//emlist[例][ruby]{
require "csv"
File.write("test.csv", <<CSV)
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
table = CSV.read("test.csv", headers: true)
p table.class # => CSV::Table
p table[0] # => #<CSV::Row "id":"1" "first name":"taro"... -
CSV
. readlines(path , options = Hash . new) -> [Array] | CSV :: Table (304.0) -
CSV ファイルを配列の配列にするために使います。 headers オプションに偽でない値を指定した場合は CSV::Table オブジェクトを返します。
...
CSV ファイルを配列の配列にするために使います。
headers オプションに偽でない値を指定した場合は CSV::Table オブジェクトを返します。
@param path CSV ファイルのパスを指定します。
@param options CSV.new のオプションと同じオプ......しなければなりません。
//emlist[例][ruby]{
require "csv"
require "pp"
File.write("test.csv", <<CSV)
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
pp CSV.read("test.csv")
# => [["id", "first name", "last name", "age"],
# ["1", "tar....../}
//emlist[例][ruby]{
require "csv"
File.write("test.csv", <<CSV)
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
table = CSV.read("test.csv", headers: true)
p table.class # => CSV::Table
p table[0] # => #<CSV::Row "id":"1" "first name":"taro"... -
CSV
# field _ size _ limit -> Integer (40.0) -
フィールドサイズの最大値を返します。
...csv"
csv = CSV.new(DATA)
csv.field_size_limit # => nil
p csv.read # => [["a", "b"], ["\n2\n2\n", ""]]
DATA.rewind
csv = CSV.new(DATA, field_size_limit: 4)
p csv.field_size_limit # => 4
csv.read # => #<CSV::MalformedCSVError: Field size exceeded on line 2.>
__END__
"a","b"
"
2
2
",""
//}
@see CSV...