| 22 |
22 |
|
| 23 |
23 |
== Class Methods
|
| 24 |
24 |
|
| 25 |
|
--- open(path, mode[, fs = nil[, rs = nil]]) {|row| ... } -> nil
|
| 26 |
|
--- open(path, mode[, fs = nil[, rs = nil]]) -> CSV::Reader
|
| 27 |
|
--- open(path, mode[, fs = nil[, rs = nil]]) -> CSV::Writer
|
|
25 |
--- open(path, mode, fs = nil, rs = nil) {|row| ... } -> nil
|
|
26 |
--- open(path, mode, fs = nil, rs = nil) -> CSV::Reader
|
|
27 |
--- open(path, mode, fs = nil, rs = nil) -> CSV::Writer
|
| 28 |
28 |
|
| 29 |
29 |
CSVファイルを読み込んでパースします。
|
| 30 |
30 |
|
| ... | ... | |
| 74 |
74 |
|
| 75 |
75 |
#@since 1.8.2
|
| 76 |
76 |
|
| 77 |
|
--- foreach(path[, rs = nil]) {|row| ... } -> nil
|
|
77 |
--- foreach(path, rs = nil) {|row| ... } -> nil
|
| 78 |
78 |
|
| 79 |
79 |
読み込みモードでファイルを開き、各行を配列でブロックに渡します。
|
| 80 |
80 |
|
| ... | ... | |
| 93 |
93 |
puts row.join(':')
|
| 94 |
94 |
}
|
| 95 |
95 |
|
| 96 |
|
--- read(path[, length = nil[, offset = nil]]) -> Array
|
|
96 |
--- read(path, length = nil, offset = nil) -> Array
|
| 97 |
97 |
|
| 98 |
98 |
path で指定された CSV ファイルを読み込み、配列の配列でデータを返します。
|
| 99 |
99 |
|
| ... | ... | |
| 106 |
106 |
パース時に""(空文字)と値なしを区別します。
|
| 107 |
107 |
例えば、a, "", , b の行をパースした場合には ["a", "", nil, "b"] の配列を返します。
|
| 108 |
108 |
|
| 109 |
|
--- readlines(path[, rs = nil]) -> Array
|
|
109 |
--- readlines(path, rs = nil) -> Array
|
| 110 |
110 |
|
| 111 |
111 |
path で指定された CSV ファイルを読み込み、配列の配列でデータを返します。
|
| 112 |
112 |
|
| ... | ... | |
| 121 |
121 |
|
| 122 |
122 |
#@end
|
| 123 |
123 |
|
| 124 |
|
--- generate(path[, fs = nil[, rs = nil]]) -> CSV::BasicWriter
|
| 125 |
|
--- generate(path[, fs = nil[, rs = nil]]) {|writer| ... } -> nil
|
|
124 |
--- generate(path, fs = nil, rs = nil) -> CSV::BasicWriter
|
|
125 |
--- generate(path, fs = nil, rs = nil) {|writer| ... } -> nil
|
| 126 |
126 |
|
| 127 |
127 |
path で指定されたファイルを書き込みモードで開き、ブロックに渡します。
|
| 128 |
128 |
ブロック未指定の場合は [[c:CSV::BasicWriter]] を返します。
|
| ... | ... | |
| 150 |
150 |
}
|
| 151 |
151 |
}
|
| 152 |
152 |
|
| 153 |
|
--- parse(str_or_readable[, fs = nil[, rs = nil]]) -> Array
|
| 154 |
|
--- parse(str_or_readable[, fs = nil[, rs = nil]]){|rows| ... } -> nil
|
|
153 |
--- parse(str_or_readable, fs = nil, rs = nil) -> Array
|
|
154 |
--- parse(str_or_readable, fs = nil, rs = nil){|rows| ... } -> nil
|
| 155 |
155 |
|
| 156 |
156 |
str_or_readable で指定された文字列をパースし配列の配列に変換、ブロックに渡します。
|
| 157 |
157 |
ブロック未指定の場合は変換された配列の配列を返します。
|
| ... | ... | |
| 167 |
167 |
p rows
|
| 168 |
168 |
}
|
| 169 |
169 |
|
| 170 |
|
--- generate_line(row[, fs = nil[, rs = nil]]) -> String
|
| 171 |
|
--- generate_line(row[, fs = nil[, rs = nil]]){|s| ... } -> nil
|
|
170 |
--- generate_line(row, fs = nil, rs = nil) -> String
|
|
171 |
--- generate_line(row, fs = nil, rs = nil){|s| ... } -> nil
|
| 172 |
172 |
|
| 173 |
173 |
row で指定された配列をパースし、fs で指定された文字をフィールドセパレータとして
|
| 174 |
174 |
1行分の文字列をブロックに渡します。
|
| ... | ... | |
| 180 |
180 |
@param rs 行区切り文字の指定。nil (デフォルト) で CrLf / Lf。
|
| 181 |
181 |
Cr を行区切りとしたい場合は ?\r を渡します。
|
| 182 |
182 |
|
| 183 |
|
--- parse_line(src[, fs = nil[, rs = nil]]) -> Array
|
| 184 |
|
--- parse_line(src[, fs = nil[, rs = nil]]){|row| ... } -> nil
|
|
183 |
--- parse_line(src, fs = nil, rs = nil) -> Array
|
|
184 |
--- parse_line(src, fs = nil, rs = nil){|row| ... } -> nil
|
| 185 |
185 |
|
| 186 |
186 |
src で指定された文字列を1行分としてパースし配列に変換、ブロックに渡します。
|
| 187 |
187 |
ブロック未指定の場合は変換された配列を返します。
|
| ... | ... | |
| 193 |
193 |
Cr を行区切りとしたい場合は ?\r を渡します。
|
| 194 |
194 |
|
| 195 |
195 |
#@if (version < "1.9.0")
|
| 196 |
|
--- generate_row(src, cells, out_dev[, fs = nil[, rs = nil]]) -> Fixnum
|
|
196 |
--- generate_row(src, cells, out_dev, fs = nil, rs = nil) -> Fixnum
|
| 197 |
197 |
|
| 198 |
198 |
src で指定された配列をパースして csv形式の文字列として(行区切り文字も含めて) out_dev に出力します。
|
| 199 |
199 |
返り値として fs で区切ったフィールド(cell)の数を返します。
|
| ... | ... | |
| 223 |
223 |
p buf #=>"a,b\n1,2\n,A,B\n"
|
| 224 |
224 |
|
| 225 |
225 |
|
| 226 |
|
--- parse_row(src, index, out_dev[, fs = nil[, rs = nil]]) -> Array
|
|
226 |
--- parse_row(src, index, out_dev, fs = nil, rs = nil) -> Array
|
| 227 |
227 |
|
| 228 |
228 |
CSV形式の文字列をパースしてCSV1行(row)分のデータを配列に変換し out_dev に出力します。
|
| 229 |
229 |
|