e621_export_downloader 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.irbrc +14 -0
- data/.ruby-version +1 -0
- data/LICENSE +21 -0
- data/README.md +148 -0
- data/Rakefile +8 -0
- data/exe/e621-export-downloader +112 -0
- data/lib/e621_export_downloader/client/options/builder/parsers.rb +42 -0
- data/lib/e621_export_downloader/client/options/builder.rb +44 -0
- data/lib/e621_export_downloader/client/options.rb +37 -0
- data/lib/e621_export_downloader/client.rb +120 -0
- data/lib/e621_export_downloader/constants.rb +17 -0
- data/lib/e621_export_downloader/export.rb +128 -0
- data/lib/e621_export_downloader/export_helper.rb +83 -0
- data/lib/e621_export_downloader/models/pool.rb +69 -0
- data/lib/e621_export_downloader/models/post.rb +166 -0
- data/lib/e621_export_downloader/models/tag.rb +41 -0
- data/lib/e621_export_downloader/models/tag_alias.rb +46 -0
- data/lib/e621_export_downloader/models/tag_implication.rb +46 -0
- data/lib/e621_export_downloader/models/wiki_page.rb +61 -0
- data/lib/e621_export_downloader/types.rb +14 -0
- data/lib/e621_export_downloader/version.rb +10 -0
- data/lib/e621_export_downloader.rb +12 -0
- data/sorbet/config +5 -0
- data/sorbet/rbi/annotations/.gitattributes +1 -0
- data/sorbet/rbi/annotations/faraday.rbi +17 -0
- data/sorbet/rbi/annotations/rainbow.rbi +269 -0
- data/sorbet/rbi/gems/.gitattributes +1 -0
- data/sorbet/rbi/gems/ast@2.4.3.rbi +550 -0
- data/sorbet/rbi/gems/benchmark@0.5.0.rbi +621 -0
- data/sorbet/rbi/gems/csv@3.3.5.rbi +4462 -0
- data/sorbet/rbi/gems/date@3.5.1.rbi +391 -0
- data/sorbet/rbi/gems/erb@6.0.4.rbi +1538 -0
- data/sorbet/rbi/gems/erubi@1.13.1.rbi +155 -0
- data/sorbet/rbi/gems/faraday-net_http@3.4.2.rbi +9 -0
- data/sorbet/rbi/gems/faraday@2.14.1.rbi +9 -0
- data/sorbet/rbi/gems/io-console@0.8.2.rbi +9 -0
- data/sorbet/rbi/gems/json@2.19.5.rbi +2240 -0
- data/sorbet/rbi/gems/language_server-protocol@3.17.0.5.rbi +9 -0
- data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +189 -0
- data/sorbet/rbi/gems/logger@1.7.0.rbi +896 -0
- data/sorbet/rbi/gems/net-http@0.9.1.rbi +4029 -0
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +147 -0
- data/sorbet/rbi/gems/parallel@2.1.0.rbi +321 -0
- data/sorbet/rbi/gems/parser@3.3.11.1.rbi +5229 -0
- data/sorbet/rbi/gems/pp@0.6.3.rbi +377 -0
- data/sorbet/rbi/gems/prettyprint@0.2.0.rbi +455 -0
- data/sorbet/rbi/gems/prism@1.9.0.rbi +42224 -0
- data/sorbet/rbi/gems/psych@5.3.1.rbi +2374 -0
- data/sorbet/rbi/gems/racc@1.8.1.rbi +165 -0
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +362 -0
- data/sorbet/rbi/gems/rake@13.4.2.rbi +3130 -0
- data/sorbet/rbi/gems/rbi@0.3.11.rbi +5505 -0
- data/sorbet/rbi/gems/rbs@4.0.2.rbi +6908 -0
- data/sorbet/rbi/gems/rdoc@7.2.0.rbi +9 -0
- data/sorbet/rbi/gems/regexp_parser@2.12.0.rbi +3398 -0
- data/sorbet/rbi/gems/reline@0.6.3.rbi +2446 -0
- data/sorbet/rbi/gems/require-hooks@0.4.0.rbi +152 -0
- data/sorbet/rbi/gems/rexml@3.4.4.rbi +4905 -0
- data/sorbet/rbi/gems/rubocop-ast@1.49.1.rbi +7062 -0
- data/sorbet/rbi/gems/rubocop-rake@0.7.1.rbi +314 -0
- data/sorbet/rbi/gems/rubocop@1.86.1.rbi +62227 -0
- data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +988 -0
- data/sorbet/rbi/gems/rubydex@0.2.0.rbi +663 -0
- data/sorbet/rbi/gems/spoom@1.7.13.rbi +6151 -0
- data/sorbet/rbi/gems/stringio@3.2.0.rbi +9 -0
- data/sorbet/rbi/gems/tapioca@0.19.1.rbi +3555 -0
- data/sorbet/rbi/gems/thor@1.5.0.rbi +3870 -0
- data/sorbet/rbi/gems/tsort@0.2.0.rbi +389 -0
- data/sorbet/rbi/gems/unicode-display_width@3.2.0.rbi +130 -0
- data/sorbet/rbi/gems/unicode-emoji@4.2.0.rbi +332 -0
- data/sorbet/rbi/gems/uri@1.1.1.rbi +2400 -0
- data/sorbet/rbi/gems/zeitwerk@2.7.5.rbi +1090 -0
- data/sorbet/rbi/shims/faraday.rbi +42 -0
- data/sorbet/rbi/todo.rbi +7 -0
- data/sorbet/tapioca/config.yml +13 -0
- data/sorbet/tapioca/require.rb +4 -0
- metadata +177 -0
|
@@ -0,0 +1,4462 @@
|
|
|
1
|
+
# typed: false
|
|
2
|
+
|
|
3
|
+
# DO NOT EDIT MANUALLY
|
|
4
|
+
# This is an autogenerated file for types exported from the `csv` gem.
|
|
5
|
+
# Please instead update this file by running `bin/tapioca gem csv`.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# pkg:gem/csv#lib/csv/core_ext/array.rb:1
|
|
9
|
+
class Array
|
|
10
|
+
include ::Enumerable
|
|
11
|
+
|
|
12
|
+
# Equivalent to CSV::generate_line(self, options)
|
|
13
|
+
#
|
|
14
|
+
# ["CSV", "data"].to_csv
|
|
15
|
+
# #=> "CSV,data\n"
|
|
16
|
+
#
|
|
17
|
+
# pkg:gem/csv#lib/csv/core_ext/array.rb:6
|
|
18
|
+
def to_csv(**options); end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# == \CSV
|
|
22
|
+
#
|
|
23
|
+
# === \CSV Data
|
|
24
|
+
#
|
|
25
|
+
# \CSV (comma-separated values) data is a text representation of a table:
|
|
26
|
+
# - A _row_ _separator_ delimits table rows.
|
|
27
|
+
# A common row separator is the newline character <tt>"\n"</tt>.
|
|
28
|
+
# - A _column_ _separator_ delimits fields in a row.
|
|
29
|
+
# A common column separator is the comma character <tt>","</tt>.
|
|
30
|
+
#
|
|
31
|
+
# This \CSV \String, with row separator <tt>"\n"</tt>
|
|
32
|
+
# and column separator <tt>","</tt>,
|
|
33
|
+
# has three rows and two columns:
|
|
34
|
+
# "foo,0\nbar,1\nbaz,2\n"
|
|
35
|
+
#
|
|
36
|
+
# Despite the name \CSV, a \CSV representation can use different separators.
|
|
37
|
+
#
|
|
38
|
+
# For more about tables, see the Wikipedia article
|
|
39
|
+
# "{Table (information)}[https://en.wikipedia.org/wiki/Table_(information)]",
|
|
40
|
+
# especially its section
|
|
41
|
+
# "{Simple table}[https://en.wikipedia.org/wiki/Table_(information)#Simple_table]"
|
|
42
|
+
#
|
|
43
|
+
# == \Class \CSV
|
|
44
|
+
#
|
|
45
|
+
# Class \CSV provides methods for:
|
|
46
|
+
# - Parsing \CSV data from a \String object, a \File (via its file path), or an \IO object.
|
|
47
|
+
# - Generating \CSV data to a \String object.
|
|
48
|
+
#
|
|
49
|
+
# To make \CSV available:
|
|
50
|
+
# require 'csv'
|
|
51
|
+
#
|
|
52
|
+
# All examples here assume that this has been done.
|
|
53
|
+
#
|
|
54
|
+
# == Keeping It Simple
|
|
55
|
+
#
|
|
56
|
+
# A \CSV object has dozens of instance methods that offer fine-grained control
|
|
57
|
+
# of parsing and generating \CSV data.
|
|
58
|
+
# For many needs, though, simpler approaches will do.
|
|
59
|
+
#
|
|
60
|
+
# This section summarizes the singleton methods in \CSV
|
|
61
|
+
# that allow you to parse and generate without explicitly
|
|
62
|
+
# creating \CSV objects.
|
|
63
|
+
# For details, follow the links.
|
|
64
|
+
#
|
|
65
|
+
# === Simple Parsing
|
|
66
|
+
#
|
|
67
|
+
# Parsing methods commonly return either of:
|
|
68
|
+
# - An \Array of Arrays of Strings:
|
|
69
|
+
# - The outer \Array is the entire "table".
|
|
70
|
+
# - Each inner \Array is a row.
|
|
71
|
+
# - Each \String is a field.
|
|
72
|
+
# - A CSV::Table object. For details, see
|
|
73
|
+
# {\CSV with Headers}[#class-CSV-label-CSV+with+Headers].
|
|
74
|
+
#
|
|
75
|
+
# ==== Parsing a \String
|
|
76
|
+
#
|
|
77
|
+
# The input to be parsed can be a string:
|
|
78
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
79
|
+
#
|
|
80
|
+
# \Method CSV.parse returns the entire \CSV data:
|
|
81
|
+
# CSV.parse(string) # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
82
|
+
#
|
|
83
|
+
# \Method CSV.parse_line returns only the first row:
|
|
84
|
+
# CSV.parse_line(string) # => ["foo", "0"]
|
|
85
|
+
#
|
|
86
|
+
# \CSV extends class \String with instance method String#parse_csv,
|
|
87
|
+
# which also returns only the first row:
|
|
88
|
+
# string.parse_csv # => ["foo", "0"]
|
|
89
|
+
#
|
|
90
|
+
# ==== Parsing Via a \File Path
|
|
91
|
+
#
|
|
92
|
+
# The input to be parsed can be in a file:
|
|
93
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
94
|
+
# path = 't.csv'
|
|
95
|
+
# File.write(path, string)
|
|
96
|
+
#
|
|
97
|
+
# \Method CSV.read returns the entire \CSV data:
|
|
98
|
+
# CSV.read(path) # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
99
|
+
#
|
|
100
|
+
# \Method CSV.foreach iterates, passing each row to the given block:
|
|
101
|
+
# CSV.foreach(path) do |row|
|
|
102
|
+
# p row
|
|
103
|
+
# end
|
|
104
|
+
# Output:
|
|
105
|
+
# ["foo", "0"]
|
|
106
|
+
# ["bar", "1"]
|
|
107
|
+
# ["baz", "2"]
|
|
108
|
+
#
|
|
109
|
+
# \Method CSV.table returns the entire \CSV data as a CSV::Table object:
|
|
110
|
+
# CSV.table(path) # => #<CSV::Table mode:col_or_row row_count:3>
|
|
111
|
+
#
|
|
112
|
+
# ==== Parsing from an Open \IO Stream
|
|
113
|
+
#
|
|
114
|
+
# The input to be parsed can be in an open \IO stream:
|
|
115
|
+
#
|
|
116
|
+
# \Method CSV.read returns the entire \CSV data:
|
|
117
|
+
# File.open(path) do |file|
|
|
118
|
+
# CSV.read(file)
|
|
119
|
+
# end # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
120
|
+
#
|
|
121
|
+
# As does method CSV.parse:
|
|
122
|
+
# File.open(path) do |file|
|
|
123
|
+
# CSV.parse(file)
|
|
124
|
+
# end # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
125
|
+
#
|
|
126
|
+
# \Method CSV.parse_line returns only the first row:
|
|
127
|
+
# File.open(path) do |file|
|
|
128
|
+
# CSV.parse_line(file)
|
|
129
|
+
# end # => ["foo", "0"]
|
|
130
|
+
#
|
|
131
|
+
# \Method CSV.foreach iterates, passing each row to the given block:
|
|
132
|
+
# File.open(path) do |file|
|
|
133
|
+
# CSV.foreach(file) do |row|
|
|
134
|
+
# p row
|
|
135
|
+
# end
|
|
136
|
+
# end
|
|
137
|
+
# Output:
|
|
138
|
+
# ["foo", "0"]
|
|
139
|
+
# ["bar", "1"]
|
|
140
|
+
# ["baz", "2"]
|
|
141
|
+
#
|
|
142
|
+
# \Method CSV.table returns the entire \CSV data as a CSV::Table object:
|
|
143
|
+
# File.open(path) do |file|
|
|
144
|
+
# CSV.table(file)
|
|
145
|
+
# end # => #<CSV::Table mode:col_or_row row_count:3>
|
|
146
|
+
#
|
|
147
|
+
# === Simple Generating
|
|
148
|
+
#
|
|
149
|
+
# \Method CSV.generate returns a \String;
|
|
150
|
+
# this example uses method CSV#<< to append the rows
|
|
151
|
+
# that are to be generated:
|
|
152
|
+
# output_string = CSV.generate do |csv|
|
|
153
|
+
# csv << ['foo', 0]
|
|
154
|
+
# csv << ['bar', 1]
|
|
155
|
+
# csv << ['baz', 2]
|
|
156
|
+
# end
|
|
157
|
+
# output_string # => "foo,0\nbar,1\nbaz,2\n"
|
|
158
|
+
#
|
|
159
|
+
# \Method CSV.generate_line returns a \String containing the single row
|
|
160
|
+
# constructed from an \Array:
|
|
161
|
+
# CSV.generate_line(['foo', '0']) # => "foo,0\n"
|
|
162
|
+
#
|
|
163
|
+
# \CSV extends class \Array with instance method <tt>Array#to_csv</tt>,
|
|
164
|
+
# which forms an \Array into a \String:
|
|
165
|
+
# ['foo', '0'].to_csv # => "foo,0\n"
|
|
166
|
+
#
|
|
167
|
+
# === "Filtering" \CSV
|
|
168
|
+
#
|
|
169
|
+
# \Method CSV.filter provides a Unix-style filter for \CSV data.
|
|
170
|
+
# The input data is processed to form the output data:
|
|
171
|
+
# in_string = "foo,0\nbar,1\nbaz,2\n"
|
|
172
|
+
# out_string = ''
|
|
173
|
+
# CSV.filter(in_string, out_string) do |row|
|
|
174
|
+
# row[0] = row[0].upcase
|
|
175
|
+
# row[1] *= 4
|
|
176
|
+
# end
|
|
177
|
+
# out_string # => "FOO,0000\nBAR,1111\nBAZ,2222\n"
|
|
178
|
+
#
|
|
179
|
+
# == \CSV Objects
|
|
180
|
+
#
|
|
181
|
+
# There are three ways to create a \CSV object:
|
|
182
|
+
# - \Method CSV.new returns a new \CSV object.
|
|
183
|
+
# - \Method CSV.instance returns a new or cached \CSV object.
|
|
184
|
+
# - \Method \CSV() also returns a new or cached \CSV object.
|
|
185
|
+
#
|
|
186
|
+
# === Instance Methods
|
|
187
|
+
#
|
|
188
|
+
# \CSV has three groups of instance methods:
|
|
189
|
+
# - Its own internally defined instance methods.
|
|
190
|
+
# - Methods included by module Enumerable.
|
|
191
|
+
# - Methods delegated to class IO. See below.
|
|
192
|
+
#
|
|
193
|
+
# ==== Delegated Methods
|
|
194
|
+
#
|
|
195
|
+
# For convenience, a CSV object will delegate to many methods in class IO.
|
|
196
|
+
# (A few have wrapper "guard code" in \CSV.) You may call:
|
|
197
|
+
# * IO#binmode
|
|
198
|
+
# * #binmode?
|
|
199
|
+
# * IO#close
|
|
200
|
+
# * IO#close_read
|
|
201
|
+
# * IO#close_write
|
|
202
|
+
# * IO#closed?
|
|
203
|
+
# * #eof
|
|
204
|
+
# * #eof?
|
|
205
|
+
# * IO#external_encoding
|
|
206
|
+
# * IO#fcntl
|
|
207
|
+
# * IO#fileno
|
|
208
|
+
# * #flock
|
|
209
|
+
# * IO#flush
|
|
210
|
+
# * IO#fsync
|
|
211
|
+
# * IO#internal_encoding
|
|
212
|
+
# * #ioctl
|
|
213
|
+
# * IO#isatty
|
|
214
|
+
# * #path
|
|
215
|
+
# * IO#pid
|
|
216
|
+
# * IO#pos
|
|
217
|
+
# * IO#pos=
|
|
218
|
+
# * IO#reopen
|
|
219
|
+
# * #rewind
|
|
220
|
+
# * IO#seek
|
|
221
|
+
# * #stat
|
|
222
|
+
# * IO#string
|
|
223
|
+
# * IO#sync
|
|
224
|
+
# * IO#sync=
|
|
225
|
+
# * IO#tell
|
|
226
|
+
# * #to_i
|
|
227
|
+
# * #to_io
|
|
228
|
+
# * IO#truncate
|
|
229
|
+
# * IO#tty?
|
|
230
|
+
#
|
|
231
|
+
# === Options
|
|
232
|
+
#
|
|
233
|
+
# The default values for options are:
|
|
234
|
+
# DEFAULT_OPTIONS = {
|
|
235
|
+
# # For both parsing and generating.
|
|
236
|
+
# col_sep: ",",
|
|
237
|
+
# row_sep: :auto,
|
|
238
|
+
# quote_char: '"',
|
|
239
|
+
# # For parsing.
|
|
240
|
+
# field_size_limit: nil,
|
|
241
|
+
# converters: nil,
|
|
242
|
+
# unconverted_fields: nil,
|
|
243
|
+
# headers: false,
|
|
244
|
+
# return_headers: false,
|
|
245
|
+
# header_converters: nil,
|
|
246
|
+
# skip_blanks: false,
|
|
247
|
+
# skip_lines: nil,
|
|
248
|
+
# liberal_parsing: false,
|
|
249
|
+
# nil_value: nil,
|
|
250
|
+
# empty_value: "",
|
|
251
|
+
# strip: false,
|
|
252
|
+
# # For generating.
|
|
253
|
+
# write_headers: nil,
|
|
254
|
+
# quote_empty: true,
|
|
255
|
+
# force_quotes: false,
|
|
256
|
+
# write_converters: nil,
|
|
257
|
+
# write_nil_value: nil,
|
|
258
|
+
# write_empty_value: "",
|
|
259
|
+
# }
|
|
260
|
+
#
|
|
261
|
+
# ==== Options for Parsing
|
|
262
|
+
#
|
|
263
|
+
# Options for parsing, described in detail below, include:
|
|
264
|
+
# - +row_sep+: Specifies the row separator; used to delimit rows.
|
|
265
|
+
# - +col_sep+: Specifies the column separator; used to delimit fields.
|
|
266
|
+
# - +quote_char+: Specifies the quote character; used to quote fields.
|
|
267
|
+
# - +field_size_limit+: Specifies the maximum field size + 1 allowed.
|
|
268
|
+
# Deprecated since 3.2.3. Use +max_field_size+ instead.
|
|
269
|
+
# - +max_field_size+: Specifies the maximum field size allowed.
|
|
270
|
+
# - +converters+: Specifies the field converters to be used.
|
|
271
|
+
# - +unconverted_fields+: Specifies whether unconverted fields are to be available.
|
|
272
|
+
# - +headers+: Specifies whether data contains headers,
|
|
273
|
+
# or specifies the headers themselves.
|
|
274
|
+
# - +return_headers+: Specifies whether headers are to be returned.
|
|
275
|
+
# - +header_converters+: Specifies the header converters to be used.
|
|
276
|
+
# - +skip_blanks+: Specifies whether blanks lines are to be ignored.
|
|
277
|
+
# - +skip_lines+: Specifies how comments lines are to be recognized.
|
|
278
|
+
# - +strip+: Specifies whether leading and trailing whitespace are to be
|
|
279
|
+
# stripped from fields. This must be compatible with +col_sep+; if it is not,
|
|
280
|
+
# then an +ArgumentError+ exception will be raised.
|
|
281
|
+
# - +liberal_parsing+: Specifies whether \CSV should attempt to parse
|
|
282
|
+
# non-compliant data.
|
|
283
|
+
# - +nil_value+: Specifies the object that is to be substituted for each null (no-text) field.
|
|
284
|
+
# - +empty_value+: Specifies the object that is to be substituted for each empty field.
|
|
285
|
+
#
|
|
286
|
+
# :include: ../doc/csv/options/common/row_sep.rdoc
|
|
287
|
+
#
|
|
288
|
+
# :include: ../doc/csv/options/common/col_sep.rdoc
|
|
289
|
+
#
|
|
290
|
+
# :include: ../doc/csv/options/common/quote_char.rdoc
|
|
291
|
+
#
|
|
292
|
+
# :include: ../doc/csv/options/parsing/field_size_limit.rdoc
|
|
293
|
+
#
|
|
294
|
+
# :include: ../doc/csv/options/parsing/converters.rdoc
|
|
295
|
+
#
|
|
296
|
+
# :include: ../doc/csv/options/parsing/unconverted_fields.rdoc
|
|
297
|
+
#
|
|
298
|
+
# :include: ../doc/csv/options/parsing/headers.rdoc
|
|
299
|
+
#
|
|
300
|
+
# :include: ../doc/csv/options/parsing/return_headers.rdoc
|
|
301
|
+
#
|
|
302
|
+
# :include: ../doc/csv/options/parsing/header_converters.rdoc
|
|
303
|
+
#
|
|
304
|
+
# :include: ../doc/csv/options/parsing/skip_blanks.rdoc
|
|
305
|
+
#
|
|
306
|
+
# :include: ../doc/csv/options/parsing/skip_lines.rdoc
|
|
307
|
+
#
|
|
308
|
+
# :include: ../doc/csv/options/parsing/strip.rdoc
|
|
309
|
+
#
|
|
310
|
+
# :include: ../doc/csv/options/parsing/liberal_parsing.rdoc
|
|
311
|
+
#
|
|
312
|
+
# :include: ../doc/csv/options/parsing/nil_value.rdoc
|
|
313
|
+
#
|
|
314
|
+
# :include: ../doc/csv/options/parsing/empty_value.rdoc
|
|
315
|
+
#
|
|
316
|
+
# ==== Options for Generating
|
|
317
|
+
#
|
|
318
|
+
# Options for generating, described in detail below, include:
|
|
319
|
+
# - +row_sep+: Specifies the row separator; used to delimit rows.
|
|
320
|
+
# - +col_sep+: Specifies the column separator; used to delimit fields.
|
|
321
|
+
# - +quote_char+: Specifies the quote character; used to quote fields.
|
|
322
|
+
# - +write_headers+: Specifies whether headers are to be written.
|
|
323
|
+
# - +force_quotes+: Specifies whether each output field is to be quoted.
|
|
324
|
+
# - +quote_empty+: Specifies whether each empty output field is to be quoted.
|
|
325
|
+
# - +write_converters+: Specifies the field converters to be used in writing.
|
|
326
|
+
# - +write_nil_value+: Specifies the object that is to be substituted for each +nil+-valued field.
|
|
327
|
+
# - +write_empty_value+: Specifies the object that is to be substituted for each empty field.
|
|
328
|
+
#
|
|
329
|
+
# :include: ../doc/csv/options/common/row_sep.rdoc
|
|
330
|
+
#
|
|
331
|
+
# :include: ../doc/csv/options/common/col_sep.rdoc
|
|
332
|
+
#
|
|
333
|
+
# :include: ../doc/csv/options/common/quote_char.rdoc
|
|
334
|
+
#
|
|
335
|
+
# :include: ../doc/csv/options/generating/write_headers.rdoc
|
|
336
|
+
#
|
|
337
|
+
# :include: ../doc/csv/options/generating/force_quotes.rdoc
|
|
338
|
+
#
|
|
339
|
+
# :include: ../doc/csv/options/generating/quote_empty.rdoc
|
|
340
|
+
#
|
|
341
|
+
# :include: ../doc/csv/options/generating/write_converters.rdoc
|
|
342
|
+
#
|
|
343
|
+
# :include: ../doc/csv/options/generating/write_nil_value.rdoc
|
|
344
|
+
#
|
|
345
|
+
# :include: ../doc/csv/options/generating/write_empty_value.rdoc
|
|
346
|
+
#
|
|
347
|
+
# === \CSV with Headers
|
|
348
|
+
#
|
|
349
|
+
# CSV allows to specify column names of CSV file, whether they are in data, or
|
|
350
|
+
# provided separately. If headers are specified, reading methods return an instance
|
|
351
|
+
# of CSV::Table, consisting of CSV::Row.
|
|
352
|
+
#
|
|
353
|
+
# # Headers are part of data
|
|
354
|
+
# data = CSV.parse(<<~ROWS, headers: true)
|
|
355
|
+
# Name,Department,Salary
|
|
356
|
+
# Bob,Engineering,1000
|
|
357
|
+
# Jane,Sales,2000
|
|
358
|
+
# John,Management,5000
|
|
359
|
+
# ROWS
|
|
360
|
+
#
|
|
361
|
+
# data.class #=> CSV::Table
|
|
362
|
+
# data.first #=> #<CSV::Row "Name":"Bob" "Department":"Engineering" "Salary":"1000">
|
|
363
|
+
# data.first.to_h #=> {"Name"=>"Bob", "Department"=>"Engineering", "Salary"=>"1000"}
|
|
364
|
+
#
|
|
365
|
+
# # Headers provided by developer
|
|
366
|
+
# data = CSV.parse('Bob,Engineering,1000', headers: %i[name department salary])
|
|
367
|
+
# data.first #=> #<CSV::Row name:"Bob" department:"Engineering" salary:"1000">
|
|
368
|
+
#
|
|
369
|
+
# === \Converters
|
|
370
|
+
#
|
|
371
|
+
# By default, each value (field or header) parsed by \CSV is formed into a \String.
|
|
372
|
+
# You can use a _field_ _converter_ or _header_ _converter_
|
|
373
|
+
# to intercept and modify the parsed values:
|
|
374
|
+
# - See {Field Converters}[#class-CSV-label-Field+Converters].
|
|
375
|
+
# - See {Header Converters}[#class-CSV-label-Header+Converters].
|
|
376
|
+
#
|
|
377
|
+
# Also by default, each value to be written during generation is written 'as-is'.
|
|
378
|
+
# You can use a _write_ _converter_ to modify values before writing.
|
|
379
|
+
# - See {Write Converters}[#class-CSV-label-Write+Converters].
|
|
380
|
+
#
|
|
381
|
+
# ==== Specifying \Converters
|
|
382
|
+
#
|
|
383
|
+
# You can specify converters for parsing or generating in the +options+
|
|
384
|
+
# argument to various \CSV methods:
|
|
385
|
+
# - Option +converters+ for converting parsed field values.
|
|
386
|
+
# - Option +header_converters+ for converting parsed header values.
|
|
387
|
+
# - Option +write_converters+ for converting values to be written (generated).
|
|
388
|
+
#
|
|
389
|
+
# There are three forms for specifying converters:
|
|
390
|
+
# - A converter proc: executable code to be used for conversion.
|
|
391
|
+
# - A converter name: the name of a stored converter.
|
|
392
|
+
# - A converter list: an array of converter procs, converter names, and converter lists.
|
|
393
|
+
#
|
|
394
|
+
# ===== Converter Procs
|
|
395
|
+
#
|
|
396
|
+
# This converter proc, +strip_converter+, accepts a value +field+
|
|
397
|
+
# and returns <tt>field.strip</tt>:
|
|
398
|
+
# strip_converter = proc {|field| field.strip }
|
|
399
|
+
# In this call to <tt>CSV.parse</tt>,
|
|
400
|
+
# the keyword argument <tt>converters: string_converter</tt>
|
|
401
|
+
# specifies that:
|
|
402
|
+
# - \Proc +string_converter+ is to be called for each parsed field.
|
|
403
|
+
# - The converter's return value is to replace the +field+ value.
|
|
404
|
+
# Example:
|
|
405
|
+
# string = " foo , 0 \n bar , 1 \n baz , 2 \n"
|
|
406
|
+
# array = CSV.parse(string, converters: strip_converter)
|
|
407
|
+
# array # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
408
|
+
#
|
|
409
|
+
# A converter proc can receive a second argument, +field_info+,
|
|
410
|
+
# that contains details about the field.
|
|
411
|
+
# This modified +strip_converter+ displays its arguments:
|
|
412
|
+
# strip_converter = proc do |field, field_info|
|
|
413
|
+
# p [field, field_info]
|
|
414
|
+
# field.strip
|
|
415
|
+
# end
|
|
416
|
+
# string = " foo , 0 \n bar , 1 \n baz , 2 \n"
|
|
417
|
+
# array = CSV.parse(string, converters: strip_converter)
|
|
418
|
+
# array # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
419
|
+
# Output:
|
|
420
|
+
# [" foo ", #<struct CSV::FieldInfo index=0, line=1, header=nil>]
|
|
421
|
+
# [" 0 ", #<struct CSV::FieldInfo index=1, line=1, header=nil>]
|
|
422
|
+
# [" bar ", #<struct CSV::FieldInfo index=0, line=2, header=nil>]
|
|
423
|
+
# [" 1 ", #<struct CSV::FieldInfo index=1, line=2, header=nil>]
|
|
424
|
+
# [" baz ", #<struct CSV::FieldInfo index=0, line=3, header=nil>]
|
|
425
|
+
# [" 2 ", #<struct CSV::FieldInfo index=1, line=3, header=nil>]
|
|
426
|
+
# Each CSV::FieldInfo object shows:
|
|
427
|
+
# - The 0-based field index.
|
|
428
|
+
# - The 1-based line index.
|
|
429
|
+
# - The field header, if any.
|
|
430
|
+
#
|
|
431
|
+
# ===== Stored \Converters
|
|
432
|
+
#
|
|
433
|
+
# A converter may be given a name and stored in a structure where
|
|
434
|
+
# the parsing methods can find it by name.
|
|
435
|
+
#
|
|
436
|
+
# The storage structure for field converters is the \Hash CSV::Converters.
|
|
437
|
+
# It has several built-in converter procs:
|
|
438
|
+
# - <tt>:integer</tt>: converts each \String-embedded integer into a true \Integer.
|
|
439
|
+
# - <tt>:float</tt>: converts each \String-embedded float into a true \Float.
|
|
440
|
+
# - <tt>:date</tt>: converts each \String-embedded date into a true \Date.
|
|
441
|
+
# - <tt>:date_time</tt>: converts each \String-embedded date-time into a true \DateTime
|
|
442
|
+
# - <tt>:time</tt>: converts each \String-embedded time into a true \Time
|
|
443
|
+
# .
|
|
444
|
+
# This example creates a converter proc, then stores it:
|
|
445
|
+
# strip_converter = proc {|field| field.strip }
|
|
446
|
+
# CSV::Converters[:strip] = strip_converter
|
|
447
|
+
# Then the parsing method call can refer to the converter
|
|
448
|
+
# by its name, <tt>:strip</tt>:
|
|
449
|
+
# string = " foo , 0 \n bar , 1 \n baz , 2 \n"
|
|
450
|
+
# array = CSV.parse(string, converters: :strip)
|
|
451
|
+
# array # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
452
|
+
#
|
|
453
|
+
# The storage structure for header converters is the \Hash CSV::HeaderConverters,
|
|
454
|
+
# which works in the same way.
|
|
455
|
+
# It also has built-in converter procs:
|
|
456
|
+
# - <tt>:downcase</tt>: Downcases each header.
|
|
457
|
+
# - <tt>:symbol</tt>: Converts each header to a \Symbol.
|
|
458
|
+
#
|
|
459
|
+
# There is no such storage structure for write headers.
|
|
460
|
+
#
|
|
461
|
+
# In order for the parsing methods to access stored converters in non-main-Ractors, the
|
|
462
|
+
# storage structure must be made shareable first.
|
|
463
|
+
# Therefore, <tt>Ractor.make_shareable(CSV::Converters)</tt> and
|
|
464
|
+
# <tt>Ractor.make_shareable(CSV::HeaderConverters)</tt> must be called before the creation
|
|
465
|
+
# of Ractors that use the converters stored in these structures. (Since making the storage
|
|
466
|
+
# structures shareable involves freezing them, any custom converters that are to be used
|
|
467
|
+
# must be added first.)
|
|
468
|
+
#
|
|
469
|
+
# ===== Converter Lists
|
|
470
|
+
#
|
|
471
|
+
# A _converter_ _list_ is an \Array that may include any assortment of:
|
|
472
|
+
# - Converter procs.
|
|
473
|
+
# - Names of stored converters.
|
|
474
|
+
# - Nested converter lists.
|
|
475
|
+
#
|
|
476
|
+
# Examples:
|
|
477
|
+
# numeric_converters = [:integer, :float]
|
|
478
|
+
# date_converters = [:date, :date_time]
|
|
479
|
+
# [numeric_converters, strip_converter]
|
|
480
|
+
# [strip_converter, date_converters, :float]
|
|
481
|
+
#
|
|
482
|
+
# Like a converter proc, a converter list may be named and stored in either
|
|
483
|
+
# \CSV::Converters or CSV::HeaderConverters:
|
|
484
|
+
# CSV::Converters[:custom] = [strip_converter, date_converters, :float]
|
|
485
|
+
# CSV::HeaderConverters[:custom] = [:downcase, :symbol]
|
|
486
|
+
#
|
|
487
|
+
# There are two built-in converter lists:
|
|
488
|
+
# CSV::Converters[:numeric] # => [:integer, :float]
|
|
489
|
+
# CSV::Converters[:all] # => [:date_time, :numeric]
|
|
490
|
+
#
|
|
491
|
+
# ==== Field \Converters
|
|
492
|
+
#
|
|
493
|
+
# With no conversion, all parsed fields in all rows become Strings:
|
|
494
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
495
|
+
# ary = CSV.parse(string)
|
|
496
|
+
# ary # => # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
497
|
+
#
|
|
498
|
+
# When you specify a field converter, each parsed field is passed to the converter;
|
|
499
|
+
# its return value becomes the stored value for the field.
|
|
500
|
+
# A converter might, for example, convert an integer embedded in a \String
|
|
501
|
+
# into a true \Integer.
|
|
502
|
+
# (In fact, that's what built-in field converter +:integer+ does.)
|
|
503
|
+
#
|
|
504
|
+
# There are three ways to use field \converters.
|
|
505
|
+
#
|
|
506
|
+
# - Using option {converters}[#class-CSV-label-Option+converters] with a parsing method:
|
|
507
|
+
# ary = CSV.parse(string, converters: :integer)
|
|
508
|
+
# ary # => [0, 1, 2] # => [["foo", 0], ["bar", 1], ["baz", 2]]
|
|
509
|
+
# - Using option {converters}[#class-CSV-label-Option+converters] with a new \CSV instance:
|
|
510
|
+
# csv = CSV.new(string, converters: :integer)
|
|
511
|
+
# # Field converters in effect:
|
|
512
|
+
# csv.converters # => [:integer]
|
|
513
|
+
# csv.read # => [["foo", 0], ["bar", 1], ["baz", 2]]
|
|
514
|
+
# - Using method #convert to add a field converter to a \CSV instance:
|
|
515
|
+
# csv = CSV.new(string)
|
|
516
|
+
# # Add a converter.
|
|
517
|
+
# csv.convert(:integer)
|
|
518
|
+
# csv.converters # => [:integer]
|
|
519
|
+
# csv.read # => [["foo", 0], ["bar", 1], ["baz", 2]]
|
|
520
|
+
#
|
|
521
|
+
# Installing a field converter does not affect already-read rows:
|
|
522
|
+
# csv = CSV.new(string)
|
|
523
|
+
# csv.shift # => ["foo", "0"]
|
|
524
|
+
# # Add a converter.
|
|
525
|
+
# csv.convert(:integer)
|
|
526
|
+
# csv.converters # => [:integer]
|
|
527
|
+
# csv.read # => [["bar", 1], ["baz", 2]]
|
|
528
|
+
#
|
|
529
|
+
# There are additional built-in \converters, and custom \converters are also supported.
|
|
530
|
+
#
|
|
531
|
+
# ===== Built-In Field \Converters
|
|
532
|
+
#
|
|
533
|
+
# The built-in field converters are in \Hash CSV::Converters:
|
|
534
|
+
# - Each key is a field converter name.
|
|
535
|
+
# - Each value is one of:
|
|
536
|
+
# - A \Proc field converter.
|
|
537
|
+
# - An \Array of field converter names.
|
|
538
|
+
#
|
|
539
|
+
# Display:
|
|
540
|
+
# CSV::Converters.each_pair do |name, value|
|
|
541
|
+
# if value.kind_of?(Proc)
|
|
542
|
+
# p [name, value.class]
|
|
543
|
+
# else
|
|
544
|
+
# p [name, value]
|
|
545
|
+
# end
|
|
546
|
+
# end
|
|
547
|
+
# Output:
|
|
548
|
+
# [:integer, Proc]
|
|
549
|
+
# [:float, Proc]
|
|
550
|
+
# [:numeric, [:integer, :float]]
|
|
551
|
+
# [:date, Proc]
|
|
552
|
+
# [:date_time, Proc]
|
|
553
|
+
# [:time, Proc]
|
|
554
|
+
# [:all, [:date_time, :numeric]]
|
|
555
|
+
#
|
|
556
|
+
# Each of these converters transcodes values to UTF-8 before attempting conversion.
|
|
557
|
+
# If a value cannot be transcoded to UTF-8 the conversion will
|
|
558
|
+
# fail and the value will remain unconverted.
|
|
559
|
+
#
|
|
560
|
+
# Converter +:integer+ converts each field that Integer() accepts:
|
|
561
|
+
# data = '0,1,2,x'
|
|
562
|
+
# # Without the converter
|
|
563
|
+
# csv = CSV.parse_line(data)
|
|
564
|
+
# csv # => ["0", "1", "2", "x"]
|
|
565
|
+
# # With the converter
|
|
566
|
+
# csv = CSV.parse_line(data, converters: :integer)
|
|
567
|
+
# csv # => [0, 1, 2, "x"]
|
|
568
|
+
#
|
|
569
|
+
# Converter +:float+ converts each field that Float() accepts:
|
|
570
|
+
# data = '1.0,3.14159,x'
|
|
571
|
+
# # Without the converter
|
|
572
|
+
# csv = CSV.parse_line(data)
|
|
573
|
+
# csv # => ["1.0", "3.14159", "x"]
|
|
574
|
+
# # With the converter
|
|
575
|
+
# csv = CSV.parse_line(data, converters: :float)
|
|
576
|
+
# csv # => [1.0, 3.14159, "x"]
|
|
577
|
+
#
|
|
578
|
+
# Converter +:numeric+ converts with both +:integer+ and +:float+..
|
|
579
|
+
#
|
|
580
|
+
# Converter +:date+ converts each field that Date::parse accepts:
|
|
581
|
+
# data = '2001-02-03,x'
|
|
582
|
+
# # Without the converter
|
|
583
|
+
# csv = CSV.parse_line(data)
|
|
584
|
+
# csv # => ["2001-02-03", "x"]
|
|
585
|
+
# # With the converter
|
|
586
|
+
# csv = CSV.parse_line(data, converters: :date)
|
|
587
|
+
# csv # => [#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>, "x"]
|
|
588
|
+
#
|
|
589
|
+
# Converter +:date_time+ converts each field that DateTime::parse accepts:
|
|
590
|
+
# data = '2020-05-07T14:59:00-05:00,x'
|
|
591
|
+
# # Without the converter
|
|
592
|
+
# csv = CSV.parse_line(data)
|
|
593
|
+
# csv # => ["2020-05-07T14:59:00-05:00", "x"]
|
|
594
|
+
# # With the converter
|
|
595
|
+
# csv = CSV.parse_line(data, converters: :date_time)
|
|
596
|
+
# csv # => [#<DateTime: 2020-05-07T14:59:00-05:00 ((2458977j,71940s,0n),-18000s,2299161j)>, "x"]
|
|
597
|
+
#
|
|
598
|
+
# Converter +time+ converts each field that Time::parse accepts:
|
|
599
|
+
# data = '2020-05-07T14:59:00-05:00,x'
|
|
600
|
+
# # Without the converter
|
|
601
|
+
# csv = CSV.parse_line(data)
|
|
602
|
+
# csv # => ["2020-05-07T14:59:00-05:00", "x"]
|
|
603
|
+
# # With the converter
|
|
604
|
+
# csv = CSV.parse_line(data, converters: :time)
|
|
605
|
+
# csv # => [2020-05-07 14:59:00 -0500, "x"]
|
|
606
|
+
#
|
|
607
|
+
# Converter +:numeric+ converts with both +:date_time+ and +:numeric+..
|
|
608
|
+
#
|
|
609
|
+
# As seen above, method #convert adds \converters to a \CSV instance,
|
|
610
|
+
# and method #converters returns an \Array of the \converters in effect:
|
|
611
|
+
# csv = CSV.new('0,1,2')
|
|
612
|
+
# csv.converters # => []
|
|
613
|
+
# csv.convert(:integer)
|
|
614
|
+
# csv.converters # => [:integer]
|
|
615
|
+
# csv.convert(:date)
|
|
616
|
+
# csv.converters # => [:integer, :date]
|
|
617
|
+
#
|
|
618
|
+
# ===== Custom Field \Converters
|
|
619
|
+
#
|
|
620
|
+
# You can define a custom field converter:
|
|
621
|
+
# strip_converter = proc {|field| field.strip }
|
|
622
|
+
# string = " foo , 0 \n bar , 1 \n baz , 2 \n"
|
|
623
|
+
# array = CSV.parse(string, converters: strip_converter)
|
|
624
|
+
# array # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
625
|
+
# You can register the converter in \Converters \Hash,
|
|
626
|
+
# which allows you to refer to it by name:
|
|
627
|
+
# CSV::Converters[:strip] = strip_converter
|
|
628
|
+
# string = " foo , 0 \n bar , 1 \n baz , 2 \n"
|
|
629
|
+
# array = CSV.parse(string, converters: :strip)
|
|
630
|
+
# array # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
631
|
+
#
|
|
632
|
+
# ==== Header \Converters
|
|
633
|
+
#
|
|
634
|
+
# Header converters operate only on headers (and not on other rows).
|
|
635
|
+
#
|
|
636
|
+
# There are three ways to use header \converters;
|
|
637
|
+
# these examples use built-in header converter +:downcase+,
|
|
638
|
+
# which downcases each parsed header.
|
|
639
|
+
#
|
|
640
|
+
# - Option +header_converters+ with a singleton parsing method:
|
|
641
|
+
# string = "Name,Count\nFoo,0\n,Bar,1\nBaz,2"
|
|
642
|
+
# tbl = CSV.parse(string, headers: true, header_converters: :downcase)
|
|
643
|
+
# tbl.class # => CSV::Table
|
|
644
|
+
# tbl.headers # => ["name", "count"]
|
|
645
|
+
#
|
|
646
|
+
# - Option +header_converters+ with a new \CSV instance:
|
|
647
|
+
# csv = CSV.new(string, header_converters: :downcase)
|
|
648
|
+
# # Header converters in effect:
|
|
649
|
+
# csv.header_converters # => [:downcase]
|
|
650
|
+
# tbl = CSV.parse(string, headers: true)
|
|
651
|
+
# tbl.headers # => ["Name", "Count"]
|
|
652
|
+
#
|
|
653
|
+
# - Method #header_convert adds a header converter to a \CSV instance:
|
|
654
|
+
# csv = CSV.new(string)
|
|
655
|
+
# # Add a header converter.
|
|
656
|
+
# csv.header_convert(:downcase)
|
|
657
|
+
# csv.header_converters # => [:downcase]
|
|
658
|
+
# tbl = CSV.parse(string, headers: true)
|
|
659
|
+
# tbl.headers # => ["Name", "Count"]
|
|
660
|
+
#
|
|
661
|
+
# ===== Built-In Header \Converters
|
|
662
|
+
#
|
|
663
|
+
# The built-in header \converters are in \Hash CSV::HeaderConverters.
|
|
664
|
+
# The keys there are the names of the \converters:
|
|
665
|
+
# CSV::HeaderConverters.keys # => [:downcase, :symbol]
|
|
666
|
+
#
|
|
667
|
+
# Converter +:downcase+ converts each header by downcasing it:
|
|
668
|
+
# string = "Name,Count\nFoo,0\n,Bar,1\nBaz,2"
|
|
669
|
+
# tbl = CSV.parse(string, headers: true, header_converters: :downcase)
|
|
670
|
+
# tbl.class # => CSV::Table
|
|
671
|
+
# tbl.headers # => ["name", "count"]
|
|
672
|
+
#
|
|
673
|
+
# Converter +:symbol+ converts each header by making it into a \Symbol:
|
|
674
|
+
# string = "Name,Count\nFoo,0\n,Bar,1\nBaz,2"
|
|
675
|
+
# tbl = CSV.parse(string, headers: true, header_converters: :symbol)
|
|
676
|
+
# tbl.headers # => [:name, :count]
|
|
677
|
+
# Details:
|
|
678
|
+
# - Strips leading and trailing whitespace.
|
|
679
|
+
# - Downcases the header.
|
|
680
|
+
# - Replaces embedded spaces with underscores.
|
|
681
|
+
# - Removes non-word characters.
|
|
682
|
+
# - Makes the string into a \Symbol.
|
|
683
|
+
#
|
|
684
|
+
# ===== Custom Header \Converters
|
|
685
|
+
#
|
|
686
|
+
# You can define a custom header converter:
|
|
687
|
+
# upcase_converter = proc {|header| header.upcase }
|
|
688
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
689
|
+
# table = CSV.parse(string, headers: true, header_converters: upcase_converter)
|
|
690
|
+
# table # => #<CSV::Table mode:col_or_row row_count:4>
|
|
691
|
+
# table.headers # => ["NAME", "VALUE"]
|
|
692
|
+
# You can register the converter in \HeaderConverters \Hash,
|
|
693
|
+
# which allows you to refer to it by name:
|
|
694
|
+
# CSV::HeaderConverters[:upcase] = upcase_converter
|
|
695
|
+
# table = CSV.parse(string, headers: true, header_converters: :upcase)
|
|
696
|
+
# table # => #<CSV::Table mode:col_or_row row_count:4>
|
|
697
|
+
# table.headers # => ["NAME", "VALUE"]
|
|
698
|
+
#
|
|
699
|
+
# ===== Write \Converters
|
|
700
|
+
#
|
|
701
|
+
# When you specify a write converter for generating \CSV,
|
|
702
|
+
# each field to be written is passed to the converter;
|
|
703
|
+
# its return value becomes the new value for the field.
|
|
704
|
+
# A converter might, for example, strip whitespace from a field.
|
|
705
|
+
#
|
|
706
|
+
# Using no write converter (all fields unmodified):
|
|
707
|
+
# output_string = CSV.generate do |csv|
|
|
708
|
+
# csv << [' foo ', 0]
|
|
709
|
+
# csv << [' bar ', 1]
|
|
710
|
+
# csv << [' baz ', 2]
|
|
711
|
+
# end
|
|
712
|
+
# output_string # => " foo ,0\n bar ,1\n baz ,2\n"
|
|
713
|
+
# Using option +write_converters+ with two custom write converters:
|
|
714
|
+
# strip_converter = proc {|field| field.respond_to?(:strip) ? field.strip : field }
|
|
715
|
+
# upcase_converter = proc {|field| field.respond_to?(:upcase) ? field.upcase : field }
|
|
716
|
+
# write_converters = [strip_converter, upcase_converter]
|
|
717
|
+
# output_string = CSV.generate(write_converters: write_converters) do |csv|
|
|
718
|
+
# csv << [' foo ', 0]
|
|
719
|
+
# csv << [' bar ', 1]
|
|
720
|
+
# csv << [' baz ', 2]
|
|
721
|
+
# end
|
|
722
|
+
# output_string # => "FOO,0\nBAR,1\nBAZ,2\n"
|
|
723
|
+
#
|
|
724
|
+
# === Character Encodings (M17n or Multilingualization)
|
|
725
|
+
#
|
|
726
|
+
# This new CSV parser is m17n savvy. The parser works in the Encoding of the IO
|
|
727
|
+
# or String object being read from or written to. Your data is never transcoded
|
|
728
|
+
# (unless you ask Ruby to transcode it for you) and will literally be parsed in
|
|
729
|
+
# the Encoding it is in. Thus CSV will return Arrays or Rows of Strings in the
|
|
730
|
+
# Encoding of your data. This is accomplished by transcoding the parser itself
|
|
731
|
+
# into your Encoding.
|
|
732
|
+
#
|
|
733
|
+
# Some transcoding must take place, of course, to accomplish this multiencoding
|
|
734
|
+
# support. For example, <tt>:col_sep</tt>, <tt>:row_sep</tt>, and
|
|
735
|
+
# <tt>:quote_char</tt> must be transcoded to match your data. Hopefully this
|
|
736
|
+
# makes the entire process feel transparent, since CSV's defaults should just
|
|
737
|
+
# magically work for your data. However, you can set these values manually in
|
|
738
|
+
# the target Encoding to avoid the translation.
|
|
739
|
+
#
|
|
740
|
+
# It's also important to note that while all of CSV's core parser is now
|
|
741
|
+
# Encoding agnostic, some features are not. For example, the built-in
|
|
742
|
+
# converters will try to transcode data to UTF-8 before making conversions.
|
|
743
|
+
# Again, you can provide custom converters that are aware of your Encodings to
|
|
744
|
+
# avoid this translation. It's just too hard for me to support native
|
|
745
|
+
# conversions in all of Ruby's Encodings.
|
|
746
|
+
#
|
|
747
|
+
# Anyway, the practical side of this is simple: make sure IO and String objects
|
|
748
|
+
# passed into CSV have the proper Encoding set and everything should just work.
|
|
749
|
+
# CSV methods that allow you to open IO objects (CSV::foreach(), CSV::open(),
|
|
750
|
+
# CSV::read(), and CSV::readlines()) do allow you to specify the Encoding.
|
|
751
|
+
#
|
|
752
|
+
# One minor exception comes when generating CSV into a String with an Encoding
|
|
753
|
+
# that is not ASCII compatible. There's no existing data for CSV to use to
|
|
754
|
+
# prepare itself and thus you will probably need to manually specify the desired
|
|
755
|
+
# Encoding for most of those cases. It will try to guess using the fields in a
|
|
756
|
+
# row of output though, when using CSV::generate_line() or Array#to_csv().
|
|
757
|
+
#
|
|
758
|
+
# I try to point out any other Encoding issues in the documentation of methods
|
|
759
|
+
# as they come up.
|
|
760
|
+
#
|
|
761
|
+
# This has been tested to the best of my ability with all non-"dummy" Encodings
|
|
762
|
+
# Ruby ships with. However, it is brave new code and may have some bugs.
|
|
763
|
+
# Please feel free to {report}[mailto:james@grayproductions.net] any issues you
|
|
764
|
+
# find with it.
|
|
765
|
+
#
|
|
766
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:3
|
|
767
|
+
class CSV
|
|
768
|
+
include ::Enumerable
|
|
769
|
+
extend ::Forwardable
|
|
770
|
+
|
|
771
|
+
# :call-seq:
|
|
772
|
+
# CSV.new(string)
|
|
773
|
+
# CSV.new(io)
|
|
774
|
+
# CSV.new(string, **options)
|
|
775
|
+
# CSV.new(io, **options)
|
|
776
|
+
#
|
|
777
|
+
# Returns the new \CSV object created using +string+ or +io+
|
|
778
|
+
# and the specified +options+.
|
|
779
|
+
#
|
|
780
|
+
# - Argument +string+ should be a \String object;
|
|
781
|
+
# it will be put into a new StringIO object positioned at the beginning.
|
|
782
|
+
# :include: ../doc/csv/arguments/io.rdoc
|
|
783
|
+
# - Argument +options+: See:
|
|
784
|
+
# * {Options for Parsing}[#class-CSV-label-Options+for+Parsing]
|
|
785
|
+
# * {Options for Generating}[#class-CSV-label-Options+for+Generating]
|
|
786
|
+
# For performance reasons, the options cannot be overridden
|
|
787
|
+
# in a \CSV object, so those specified here will endure.
|
|
788
|
+
#
|
|
789
|
+
# In addition to the \CSV instance methods, several \IO methods are delegated.
|
|
790
|
+
# See {Delegated Methods}[#class-CSV-label-Delegated+Methods].
|
|
791
|
+
#
|
|
792
|
+
# ---
|
|
793
|
+
#
|
|
794
|
+
# Create a \CSV object from a \String object:
|
|
795
|
+
# csv = CSV.new('foo,0')
|
|
796
|
+
#
|
|
797
|
+
# Create a \CSV object from a \File object:
|
|
798
|
+
# File.write('t.csv', 'foo,0')
|
|
799
|
+
# csv = CSV.new(File.open('t.csv'))
|
|
800
|
+
#
|
|
801
|
+
# ---
|
|
802
|
+
#
|
|
803
|
+
# Raises an exception if the argument is +nil+:
|
|
804
|
+
# # Raises ArgumentError (Cannot parse nil as CSV):
|
|
805
|
+
# CSV.new(nil)
|
|
806
|
+
#
|
|
807
|
+
# pkg:gem/csv#lib/csv.rb:2034
|
|
808
|
+
def initialize(data, col_sep: T.unsafe(nil), row_sep: T.unsafe(nil), quote_char: T.unsafe(nil), field_size_limit: T.unsafe(nil), max_field_size: T.unsafe(nil), converters: T.unsafe(nil), unconverted_fields: T.unsafe(nil), headers: T.unsafe(nil), return_headers: T.unsafe(nil), write_headers: T.unsafe(nil), header_converters: T.unsafe(nil), skip_blanks: T.unsafe(nil), force_quotes: T.unsafe(nil), skip_lines: T.unsafe(nil), liberal_parsing: T.unsafe(nil), internal_encoding: T.unsafe(nil), external_encoding: T.unsafe(nil), encoding: T.unsafe(nil), nil_value: T.unsafe(nil), empty_value: T.unsafe(nil), strip: T.unsafe(nil), quote_empty: T.unsafe(nil), write_converters: T.unsafe(nil), write_nil_value: T.unsafe(nil), write_empty_value: T.unsafe(nil)); end
|
|
809
|
+
|
|
810
|
+
# :call-seq:
|
|
811
|
+
# csv << row -> self
|
|
812
|
+
#
|
|
813
|
+
# Appends a row to +self+.
|
|
814
|
+
#
|
|
815
|
+
# - Argument +row+ must be an \Array object or a CSV::Row object.
|
|
816
|
+
# - The output stream must be open for writing.
|
|
817
|
+
#
|
|
818
|
+
# ---
|
|
819
|
+
#
|
|
820
|
+
# Append Arrays:
|
|
821
|
+
# CSV.generate do |csv|
|
|
822
|
+
# csv << ['foo', 0]
|
|
823
|
+
# csv << ['bar', 1]
|
|
824
|
+
# csv << ['baz', 2]
|
|
825
|
+
# end # => "foo,0\nbar,1\nbaz,2\n"
|
|
826
|
+
#
|
|
827
|
+
# Append CSV::Rows:
|
|
828
|
+
# headers = []
|
|
829
|
+
# CSV.generate do |csv|
|
|
830
|
+
# csv << CSV::Row.new(headers, ['foo', 0])
|
|
831
|
+
# csv << CSV::Row.new(headers, ['bar', 1])
|
|
832
|
+
# csv << CSV::Row.new(headers, ['baz', 2])
|
|
833
|
+
# end # => "foo,0\nbar,1\nbaz,2\n"
|
|
834
|
+
#
|
|
835
|
+
# Headers in CSV::Row objects are not appended:
|
|
836
|
+
# headers = ['Name', 'Count']
|
|
837
|
+
# CSV.generate do |csv|
|
|
838
|
+
# csv << CSV::Row.new(headers, ['foo', 0])
|
|
839
|
+
# csv << CSV::Row.new(headers, ['bar', 1])
|
|
840
|
+
# csv << CSV::Row.new(headers, ['baz', 2])
|
|
841
|
+
# end # => "foo,0\nbar,1\nbaz,2\n"
|
|
842
|
+
#
|
|
843
|
+
# ---
|
|
844
|
+
#
|
|
845
|
+
# Raises an exception if +row+ is not an \Array or \CSV::Row:
|
|
846
|
+
# CSV.generate do |csv|
|
|
847
|
+
# # Raises NoMethodError (undefined method `collect' for :foo:Symbol)
|
|
848
|
+
# csv << :foo
|
|
849
|
+
# end
|
|
850
|
+
#
|
|
851
|
+
# Raises an exception if the output stream is not opened for writing:
|
|
852
|
+
# path = 't.csv'
|
|
853
|
+
# File.write(path, '')
|
|
854
|
+
# File.open(path) do |file|
|
|
855
|
+
# CSV.open(file) do |csv|
|
|
856
|
+
# # Raises IOError (not opened for writing)
|
|
857
|
+
# csv << ['foo', 0]
|
|
858
|
+
# end
|
|
859
|
+
# end
|
|
860
|
+
#
|
|
861
|
+
# pkg:gem/csv#lib/csv.rb:2507
|
|
862
|
+
def <<(row); end
|
|
863
|
+
|
|
864
|
+
# pkg:gem/csv#lib/csv.rb:2511
|
|
865
|
+
def add_row(row); end
|
|
866
|
+
|
|
867
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
868
|
+
def binmode(*args, **_arg1, &block); end
|
|
869
|
+
|
|
870
|
+
# pkg:gem/csv#lib/csv.rb:2396
|
|
871
|
+
def binmode?; end
|
|
872
|
+
|
|
873
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
874
|
+
def close(*args, **_arg1, &block); end
|
|
875
|
+
|
|
876
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
877
|
+
def close_read(*args, **_arg1, &block); end
|
|
878
|
+
|
|
879
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
880
|
+
def close_write(*args, **_arg1, &block); end
|
|
881
|
+
|
|
882
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
883
|
+
def closed?(*args, **_arg1, &block); end
|
|
884
|
+
|
|
885
|
+
# :call-seq:
|
|
886
|
+
# csv.col_sep -> string
|
|
887
|
+
#
|
|
888
|
+
# Returns the encoded column separator; used for parsing and writing;
|
|
889
|
+
# see {Option +col_sep+}[#class-CSV-label-Option+col_sep]:
|
|
890
|
+
# CSV.new('').col_sep # => ","
|
|
891
|
+
#
|
|
892
|
+
# pkg:gem/csv#lib/csv.rb:2144
|
|
893
|
+
def col_sep; end
|
|
894
|
+
|
|
895
|
+
# :call-seq:
|
|
896
|
+
# convert(converter_name) -> array_of_procs
|
|
897
|
+
# convert {|field, field_info| ... } -> array_of_procs
|
|
898
|
+
#
|
|
899
|
+
# - With no block, installs a field converter (a \Proc).
|
|
900
|
+
# - With a block, defines and installs a custom field converter.
|
|
901
|
+
# - Returns the \Array of installed field converters.
|
|
902
|
+
#
|
|
903
|
+
# - Argument +converter_name+, if given, should be the name
|
|
904
|
+
# of an existing field converter.
|
|
905
|
+
#
|
|
906
|
+
# See {Field Converters}[#class-CSV-label-Field+Converters].
|
|
907
|
+
# ---
|
|
908
|
+
#
|
|
909
|
+
# With no block, installs a field converter:
|
|
910
|
+
# csv = CSV.new('')
|
|
911
|
+
# csv.convert(:integer)
|
|
912
|
+
# csv.convert(:float)
|
|
913
|
+
# csv.convert(:date)
|
|
914
|
+
# csv.converters # => [:integer, :float, :date]
|
|
915
|
+
#
|
|
916
|
+
# ---
|
|
917
|
+
#
|
|
918
|
+
# The block, if given, is called for each field:
|
|
919
|
+
# - Argument +field+ is the field value.
|
|
920
|
+
# - Argument +field_info+ is a CSV::FieldInfo object
|
|
921
|
+
# containing details about the field.
|
|
922
|
+
#
|
|
923
|
+
# The examples here assume the prior execution of:
|
|
924
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
925
|
+
# path = 't.csv'
|
|
926
|
+
# File.write(path, string)
|
|
927
|
+
#
|
|
928
|
+
# Example giving a block:
|
|
929
|
+
# csv = CSV.open(path)
|
|
930
|
+
# csv.convert {|field, field_info| p [field, field_info]; field.upcase }
|
|
931
|
+
# csv.read # => [["FOO", "0"], ["BAR", "1"], ["BAZ", "2"]]
|
|
932
|
+
#
|
|
933
|
+
# Output:
|
|
934
|
+
# ["foo", #<struct CSV::FieldInfo index=0, line=1, header=nil>]
|
|
935
|
+
# ["0", #<struct CSV::FieldInfo index=1, line=1, header=nil>]
|
|
936
|
+
# ["bar", #<struct CSV::FieldInfo index=0, line=2, header=nil>]
|
|
937
|
+
# ["1", #<struct CSV::FieldInfo index=1, line=2, header=nil>]
|
|
938
|
+
# ["baz", #<struct CSV::FieldInfo index=0, line=3, header=nil>]
|
|
939
|
+
# ["2", #<struct CSV::FieldInfo index=1, line=3, header=nil>]
|
|
940
|
+
#
|
|
941
|
+
# The block need not return a \String object:
|
|
942
|
+
# csv = CSV.open(path)
|
|
943
|
+
# csv.convert {|field, field_info| field.to_sym }
|
|
944
|
+
# csv.read # => [[:foo, :"0"], [:bar, :"1"], [:baz, :"2"]]
|
|
945
|
+
#
|
|
946
|
+
# If +converter_name+ is given, the block is not called:
|
|
947
|
+
# csv = CSV.open(path)
|
|
948
|
+
# csv.convert(:integer) {|field, field_info| fail 'Cannot happen' }
|
|
949
|
+
# csv.read # => [["foo", 0], ["bar", 1], ["baz", 2]]
|
|
950
|
+
#
|
|
951
|
+
# ---
|
|
952
|
+
#
|
|
953
|
+
# Raises a parse-time exception if +converter_name+ is not the name of a built-in
|
|
954
|
+
# field converter:
|
|
955
|
+
# csv = CSV.open(path)
|
|
956
|
+
# csv.convert(:nosuch) => [nil]
|
|
957
|
+
# # Raises NoMethodError (undefined method `arity' for nil:NilClass)
|
|
958
|
+
# csv.read
|
|
959
|
+
#
|
|
960
|
+
# pkg:gem/csv#lib/csv.rb:2578
|
|
961
|
+
def convert(name = T.unsafe(nil), &converter); end
|
|
962
|
+
|
|
963
|
+
# :call-seq:
|
|
964
|
+
# csv.converters -> array
|
|
965
|
+
#
|
|
966
|
+
# Returns an \Array containing field converters;
|
|
967
|
+
# see {Field Converters}[#class-CSV-label-Field+Converters]:
|
|
968
|
+
# csv = CSV.new('')
|
|
969
|
+
# csv.converters # => []
|
|
970
|
+
# csv.convert(:integer)
|
|
971
|
+
# csv.converters # => [:integer]
|
|
972
|
+
# csv.convert(proc {|x| x.to_s })
|
|
973
|
+
# csv.converters
|
|
974
|
+
#
|
|
975
|
+
# Notes that you need to call
|
|
976
|
+
# +Ractor.make_shareable(CSV::Converters)+ on the main Ractor to use
|
|
977
|
+
# this method.
|
|
978
|
+
#
|
|
979
|
+
# pkg:gem/csv#lib/csv.rb:2217
|
|
980
|
+
def converters; end
|
|
981
|
+
|
|
982
|
+
# :call-seq:
|
|
983
|
+
# csv.each -> enumerator
|
|
984
|
+
# csv.each {|row| ...}
|
|
985
|
+
#
|
|
986
|
+
# Calls the block with each successive row.
|
|
987
|
+
# The data source must be opened for reading.
|
|
988
|
+
#
|
|
989
|
+
# Without headers:
|
|
990
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
991
|
+
# csv = CSV.new(string)
|
|
992
|
+
# csv.each do |row|
|
|
993
|
+
# p row
|
|
994
|
+
# end
|
|
995
|
+
# Output:
|
|
996
|
+
# ["foo", "0"]
|
|
997
|
+
# ["bar", "1"]
|
|
998
|
+
# ["baz", "2"]
|
|
999
|
+
#
|
|
1000
|
+
# With headers:
|
|
1001
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
1002
|
+
# csv = CSV.new(string, headers: true)
|
|
1003
|
+
# csv.each do |row|
|
|
1004
|
+
# p row
|
|
1005
|
+
# end
|
|
1006
|
+
# Output:
|
|
1007
|
+
# <CSV::Row "Name":"foo" "Value":"0">
|
|
1008
|
+
# <CSV::Row "Name":"bar" "Value":"1">
|
|
1009
|
+
# <CSV::Row "Name":"baz" "Value":"2">
|
|
1010
|
+
#
|
|
1011
|
+
# ---
|
|
1012
|
+
#
|
|
1013
|
+
# Raises an exception if the source is not opened for reading:
|
|
1014
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1015
|
+
# csv = CSV.new(string)
|
|
1016
|
+
# csv.close
|
|
1017
|
+
# # Raises IOError (not opened for reading)
|
|
1018
|
+
# csv.each do |row|
|
|
1019
|
+
# p row
|
|
1020
|
+
# end
|
|
1021
|
+
#
|
|
1022
|
+
# pkg:gem/csv#lib/csv.rb:2689
|
|
1023
|
+
def each(&block); end
|
|
1024
|
+
|
|
1025
|
+
# :call-seq:
|
|
1026
|
+
# csv.encoding -> encoding
|
|
1027
|
+
#
|
|
1028
|
+
# Returns the encoding used for parsing and generating;
|
|
1029
|
+
# see {Character Encodings (M17n or Multilingualization)}[#class-CSV-label-Character+Encodings+-28M17n+or+Multilingualization-29]:
|
|
1030
|
+
# CSV.new('').encoding # => #<Encoding:UTF-8>
|
|
1031
|
+
#
|
|
1032
|
+
# pkg:gem/csv#lib/csv.rb:2327
|
|
1033
|
+
def encoding; end
|
|
1034
|
+
|
|
1035
|
+
# pkg:gem/csv#lib/csv.rb:2444
|
|
1036
|
+
def eof; end
|
|
1037
|
+
|
|
1038
|
+
# pkg:gem/csv#lib/csv.rb:2432
|
|
1039
|
+
def eof?; end
|
|
1040
|
+
|
|
1041
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1042
|
+
def external_encoding(*args, **_arg1, &block); end
|
|
1043
|
+
|
|
1044
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1045
|
+
def fcntl(*args, **_arg1, &block); end
|
|
1046
|
+
|
|
1047
|
+
# :call-seq:
|
|
1048
|
+
# csv.field_size_limit -> integer or nil
|
|
1049
|
+
#
|
|
1050
|
+
# Returns the limit for field size; used for parsing;
|
|
1051
|
+
# see {Option +field_size_limit+}[#class-CSV-label-Option+field_size_limit]:
|
|
1052
|
+
# CSV.new('').field_size_limit # => nil
|
|
1053
|
+
#
|
|
1054
|
+
# Deprecated since 3.2.3. Use +max_field_size+ instead.
|
|
1055
|
+
#
|
|
1056
|
+
# pkg:gem/csv#lib/csv.rb:2176
|
|
1057
|
+
def field_size_limit; end
|
|
1058
|
+
|
|
1059
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1060
|
+
def fileno(*args, **_arg1, &block); end
|
|
1061
|
+
|
|
1062
|
+
# pkg:gem/csv#lib/csv.rb:2404
|
|
1063
|
+
def flock(*args); end
|
|
1064
|
+
|
|
1065
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1066
|
+
def flush(*args, **_arg1, &block); end
|
|
1067
|
+
|
|
1068
|
+
# :call-seq:
|
|
1069
|
+
# csv.force_quotes? -> true or false
|
|
1070
|
+
#
|
|
1071
|
+
# Returns the value that determines whether all output fields are to be quoted;
|
|
1072
|
+
# used for generating;
|
|
1073
|
+
# see {Option +force_quotes+}[#class-CSV-label-Option+force_quotes]:
|
|
1074
|
+
# CSV.new('').force_quotes? # => false
|
|
1075
|
+
#
|
|
1076
|
+
# pkg:gem/csv#lib/csv.rb:2307
|
|
1077
|
+
def force_quotes?; end
|
|
1078
|
+
|
|
1079
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1080
|
+
def fsync(*args, **_arg1, &block); end
|
|
1081
|
+
|
|
1082
|
+
# pkg:gem/csv#lib/csv.rb:2814
|
|
1083
|
+
def gets; end
|
|
1084
|
+
|
|
1085
|
+
# The block need not return a \String object:
|
|
1086
|
+
# csv = CSV.open(path, headers: true)
|
|
1087
|
+
# csv.header_convert {|header, field_info| header.to_sym }
|
|
1088
|
+
# table = csv.read
|
|
1089
|
+
# table.headers # => [:Name, :Value]
|
|
1090
|
+
#
|
|
1091
|
+
# If +converter_name+ is given, the block is not called:
|
|
1092
|
+
# csv = CSV.open(path, headers: true)
|
|
1093
|
+
# csv.header_convert(:downcase) {|header, field_info| fail 'Cannot happen' }
|
|
1094
|
+
# table = csv.read
|
|
1095
|
+
# table.headers # => ["name", "value"]
|
|
1096
|
+
# ---
|
|
1097
|
+
#
|
|
1098
|
+
# Raises a parse-time exception if +converter_name+ is not the name of a built-in
|
|
1099
|
+
# field converter:
|
|
1100
|
+
# csv = CSV.open(path, headers: true)
|
|
1101
|
+
# csv.header_convert(:nosuch)
|
|
1102
|
+
# # Raises NoMethodError (undefined method `arity' for nil:NilClass)
|
|
1103
|
+
# csv.read
|
|
1104
|
+
#
|
|
1105
|
+
# pkg:gem/csv#lib/csv.rb:2644
|
|
1106
|
+
def header_convert(name = T.unsafe(nil), &converter); end
|
|
1107
|
+
|
|
1108
|
+
# :call-seq:
|
|
1109
|
+
# csv.header_converters -> array
|
|
1110
|
+
#
|
|
1111
|
+
# Returns an \Array containing header converters; used for parsing;
|
|
1112
|
+
# see {Header Converters}[#class-CSV-label-Header+Converters]:
|
|
1113
|
+
# CSV.new('').header_converters # => []
|
|
1114
|
+
#
|
|
1115
|
+
# Notes that you need to call
|
|
1116
|
+
# +Ractor.make_shareable(CSV::HeaderConverters)+ on the main Ractor
|
|
1117
|
+
# to use this method.
|
|
1118
|
+
#
|
|
1119
|
+
# pkg:gem/csv#lib/csv.rb:2283
|
|
1120
|
+
def header_converters; end
|
|
1121
|
+
|
|
1122
|
+
# :call-seq:
|
|
1123
|
+
# csv.header_row? -> true or false
|
|
1124
|
+
#
|
|
1125
|
+
# Returns +true+ if the next row to be read is a header row\;
|
|
1126
|
+
# +false+ otherwise.
|
|
1127
|
+
#
|
|
1128
|
+
# Without headers:
|
|
1129
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1130
|
+
# csv = CSV.new(string)
|
|
1131
|
+
# csv.header_row? # => false
|
|
1132
|
+
#
|
|
1133
|
+
# With headers:
|
|
1134
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
1135
|
+
# csv = CSV.new(string, headers: true)
|
|
1136
|
+
# csv.header_row? # => true
|
|
1137
|
+
# csv.shift # => #<CSV::Row "Name":"foo" "Value":"0">
|
|
1138
|
+
# csv.header_row? # => false
|
|
1139
|
+
#
|
|
1140
|
+
# ---
|
|
1141
|
+
#
|
|
1142
|
+
# Raises an exception if the source is not opened for reading:
|
|
1143
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1144
|
+
# csv = CSV.new(string)
|
|
1145
|
+
# csv.close
|
|
1146
|
+
# # Raises IOError (not opened for reading)
|
|
1147
|
+
# csv.header_row?
|
|
1148
|
+
#
|
|
1149
|
+
# pkg:gem/csv#lib/csv.rb:2766
|
|
1150
|
+
def header_row?; end
|
|
1151
|
+
|
|
1152
|
+
# :call-seq:
|
|
1153
|
+
# csv.headers -> object
|
|
1154
|
+
#
|
|
1155
|
+
# Returns the value that determines whether headers are used; used for parsing;
|
|
1156
|
+
# see {Option +headers+}[#class-CSV-label-Option+headers]:
|
|
1157
|
+
# CSV.new('').headers # => nil
|
|
1158
|
+
#
|
|
1159
|
+
# pkg:gem/csv#lib/csv.rb:2241
|
|
1160
|
+
def headers; end
|
|
1161
|
+
|
|
1162
|
+
# :call-seq:
|
|
1163
|
+
# csv.inspect -> string
|
|
1164
|
+
#
|
|
1165
|
+
# Returns a \String showing certain properties of +self+:
|
|
1166
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
1167
|
+
# csv = CSV.new(string, headers: true)
|
|
1168
|
+
# s = csv.inspect
|
|
1169
|
+
#
|
|
1170
|
+
# pkg:gem/csv#lib/csv.rb:2825
|
|
1171
|
+
def inspect; end
|
|
1172
|
+
|
|
1173
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1174
|
+
def internal_encoding(*args, **_arg1, &block); end
|
|
1175
|
+
|
|
1176
|
+
# pkg:gem/csv#lib/csv.rb:2409
|
|
1177
|
+
def ioctl(*args); end
|
|
1178
|
+
|
|
1179
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1180
|
+
def isatty(*args, **_arg1, &block); end
|
|
1181
|
+
|
|
1182
|
+
# :call-seq:
|
|
1183
|
+
# csv.liberal_parsing? -> true or false
|
|
1184
|
+
#
|
|
1185
|
+
# Returns the value that determines whether illegal input is to be handled; used for parsing;
|
|
1186
|
+
# see {Option +liberal_parsing+}[#class-CSV-label-Option+liberal_parsing]:
|
|
1187
|
+
# CSV.new('').liberal_parsing? # => false
|
|
1188
|
+
#
|
|
1189
|
+
# pkg:gem/csv#lib/csv.rb:2317
|
|
1190
|
+
def liberal_parsing?; end
|
|
1191
|
+
|
|
1192
|
+
# :call-seq:
|
|
1193
|
+
# csv.line -> array
|
|
1194
|
+
#
|
|
1195
|
+
# Returns the line most recently read:
|
|
1196
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1197
|
+
# path = 't.csv'
|
|
1198
|
+
# File.write(path, string)
|
|
1199
|
+
# CSV.open(path) do |csv|
|
|
1200
|
+
# csv.each do |row|
|
|
1201
|
+
# p [csv.lineno, csv.line]
|
|
1202
|
+
# end
|
|
1203
|
+
# end
|
|
1204
|
+
# Output:
|
|
1205
|
+
# [1, "foo,0\n"]
|
|
1206
|
+
# [2, "bar,1\n"]
|
|
1207
|
+
# [3, "baz,2\n"]
|
|
1208
|
+
#
|
|
1209
|
+
# pkg:gem/csv#lib/csv.rb:2382
|
|
1210
|
+
def line; end
|
|
1211
|
+
|
|
1212
|
+
# :call-seq:
|
|
1213
|
+
# csv.line_no -> integer
|
|
1214
|
+
#
|
|
1215
|
+
# Returns the count of the rows parsed or generated.
|
|
1216
|
+
#
|
|
1217
|
+
# Parsing:
|
|
1218
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1219
|
+
# path = 't.csv'
|
|
1220
|
+
# File.write(path, string)
|
|
1221
|
+
# CSV.open(path) do |csv|
|
|
1222
|
+
# csv.each do |row|
|
|
1223
|
+
# p [csv.lineno, row]
|
|
1224
|
+
# end
|
|
1225
|
+
# end
|
|
1226
|
+
# Output:
|
|
1227
|
+
# [1, ["foo", "0"]]
|
|
1228
|
+
# [2, ["bar", "1"]]
|
|
1229
|
+
# [3, ["baz", "2"]]
|
|
1230
|
+
#
|
|
1231
|
+
# Generating:
|
|
1232
|
+
# CSV.generate do |csv|
|
|
1233
|
+
# p csv.lineno; csv << ['foo', 0]
|
|
1234
|
+
# p csv.lineno; csv << ['bar', 1]
|
|
1235
|
+
# p csv.lineno; csv << ['baz', 2]
|
|
1236
|
+
# end
|
|
1237
|
+
# Output:
|
|
1238
|
+
# 0
|
|
1239
|
+
# 1
|
|
1240
|
+
# 2
|
|
1241
|
+
#
|
|
1242
|
+
# pkg:gem/csv#lib/csv.rb:2358
|
|
1243
|
+
def lineno; end
|
|
1244
|
+
|
|
1245
|
+
# :call-seq:
|
|
1246
|
+
# csv.max_field_size -> integer or nil
|
|
1247
|
+
#
|
|
1248
|
+
# Returns the limit for field size; used for parsing;
|
|
1249
|
+
# see {Option +max_field_size+}[#class-CSV-label-Option+max_field_size]:
|
|
1250
|
+
# CSV.new('').max_field_size # => nil
|
|
1251
|
+
#
|
|
1252
|
+
# Since 3.2.3.
|
|
1253
|
+
#
|
|
1254
|
+
# pkg:gem/csv#lib/csv.rb:2188
|
|
1255
|
+
def max_field_size; end
|
|
1256
|
+
|
|
1257
|
+
# pkg:gem/csv#lib/csv.rb:2414
|
|
1258
|
+
def path; end
|
|
1259
|
+
|
|
1260
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1261
|
+
def pid(*args, **_arg1, &block); end
|
|
1262
|
+
|
|
1263
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1264
|
+
def pos(*args, **_arg1, &block); end
|
|
1265
|
+
|
|
1266
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1267
|
+
def pos=(*args, **_arg1, &block); end
|
|
1268
|
+
|
|
1269
|
+
# pkg:gem/csv#lib/csv.rb:2512
|
|
1270
|
+
def puts(row); end
|
|
1271
|
+
|
|
1272
|
+
# :call-seq:
|
|
1273
|
+
# csv.quote_char -> character
|
|
1274
|
+
#
|
|
1275
|
+
# Returns the encoded quote character; used for parsing and writing;
|
|
1276
|
+
# see {Option +quote_char+}[#class-CSV-label-Option+quote_char]:
|
|
1277
|
+
# CSV.new('').quote_char # => "\""
|
|
1278
|
+
#
|
|
1279
|
+
# pkg:gem/csv#lib/csv.rb:2164
|
|
1280
|
+
def quote_char; end
|
|
1281
|
+
|
|
1282
|
+
# :call-seq:
|
|
1283
|
+
# csv.read -> array or csv_table
|
|
1284
|
+
#
|
|
1285
|
+
# Forms the remaining rows from +self+ into:
|
|
1286
|
+
# - A CSV::Table object, if headers are in use.
|
|
1287
|
+
# - An \Array of Arrays, otherwise.
|
|
1288
|
+
#
|
|
1289
|
+
# The data source must be opened for reading.
|
|
1290
|
+
#
|
|
1291
|
+
# Without headers:
|
|
1292
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1293
|
+
# path = 't.csv'
|
|
1294
|
+
# File.write(path, string)
|
|
1295
|
+
# csv = CSV.open(path)
|
|
1296
|
+
# csv.read # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
1297
|
+
#
|
|
1298
|
+
# With headers:
|
|
1299
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
1300
|
+
# path = 't.csv'
|
|
1301
|
+
# File.write(path, string)
|
|
1302
|
+
# csv = CSV.open(path, headers: true)
|
|
1303
|
+
# csv.read # => #<CSV::Table mode:col_or_row row_count:4>
|
|
1304
|
+
#
|
|
1305
|
+
# ---
|
|
1306
|
+
#
|
|
1307
|
+
# Raises an exception if the source is not opened for reading:
|
|
1308
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1309
|
+
# csv = CSV.new(string)
|
|
1310
|
+
# csv.close
|
|
1311
|
+
# # Raises IOError (not opened for reading)
|
|
1312
|
+
# csv.read
|
|
1313
|
+
#
|
|
1314
|
+
# pkg:gem/csv#lib/csv.rb:2730
|
|
1315
|
+
def read; end
|
|
1316
|
+
|
|
1317
|
+
# pkg:gem/csv#lib/csv.rb:2815
|
|
1318
|
+
def readline; end
|
|
1319
|
+
|
|
1320
|
+
# pkg:gem/csv#lib/csv.rb:2738
|
|
1321
|
+
def readlines; end
|
|
1322
|
+
|
|
1323
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1324
|
+
def reopen(*args, **_arg1, &block); end
|
|
1325
|
+
|
|
1326
|
+
# :call-seq:
|
|
1327
|
+
# csv.return_headers? -> true or false
|
|
1328
|
+
#
|
|
1329
|
+
# Returns the value that determines whether headers are to be returned; used for parsing;
|
|
1330
|
+
# see {Option +return_headers+}[#class-CSV-label-Option+return_headers]:
|
|
1331
|
+
# CSV.new('').return_headers? # => false
|
|
1332
|
+
#
|
|
1333
|
+
# pkg:gem/csv#lib/csv.rb:2259
|
|
1334
|
+
def return_headers?; end
|
|
1335
|
+
|
|
1336
|
+
# Rewinds the underlying IO object and resets CSV's lineno() counter.
|
|
1337
|
+
#
|
|
1338
|
+
# pkg:gem/csv#lib/csv.rb:2447
|
|
1339
|
+
def rewind; end
|
|
1340
|
+
|
|
1341
|
+
# :call-seq:
|
|
1342
|
+
# csv.row_sep -> string
|
|
1343
|
+
#
|
|
1344
|
+
# Returns the encoded row separator; used for parsing and writing;
|
|
1345
|
+
# see {Option +row_sep+}[#class-CSV-label-Option+row_sep]:
|
|
1346
|
+
# CSV.new('').row_sep # => "\n"
|
|
1347
|
+
#
|
|
1348
|
+
# pkg:gem/csv#lib/csv.rb:2154
|
|
1349
|
+
def row_sep; end
|
|
1350
|
+
|
|
1351
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1352
|
+
def seek(*args, **_arg1, &block); end
|
|
1353
|
+
|
|
1354
|
+
# :call-seq:
|
|
1355
|
+
# csv.shift -> array, csv_row, or nil
|
|
1356
|
+
#
|
|
1357
|
+
# Returns the next row of data as:
|
|
1358
|
+
# - An \Array if no headers are used.
|
|
1359
|
+
# - A CSV::Row object if headers are used.
|
|
1360
|
+
#
|
|
1361
|
+
# The data source must be opened for reading.
|
|
1362
|
+
#
|
|
1363
|
+
# Without headers:
|
|
1364
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1365
|
+
# csv = CSV.new(string)
|
|
1366
|
+
# csv.shift # => ["foo", "0"]
|
|
1367
|
+
# csv.shift # => ["bar", "1"]
|
|
1368
|
+
# csv.shift # => ["baz", "2"]
|
|
1369
|
+
# csv.shift # => nil
|
|
1370
|
+
#
|
|
1371
|
+
# With headers:
|
|
1372
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
1373
|
+
# csv = CSV.new(string, headers: true)
|
|
1374
|
+
# csv.shift # => #<CSV::Row "Name":"foo" "Value":"0">
|
|
1375
|
+
# csv.shift # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
1376
|
+
# csv.shift # => #<CSV::Row "Name":"baz" "Value":"2">
|
|
1377
|
+
# csv.shift # => nil
|
|
1378
|
+
#
|
|
1379
|
+
# ---
|
|
1380
|
+
#
|
|
1381
|
+
# Raises an exception if the source is not opened for reading:
|
|
1382
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1383
|
+
# csv = CSV.new(string)
|
|
1384
|
+
# csv.close
|
|
1385
|
+
# # Raises IOError (not opened for reading)
|
|
1386
|
+
# csv.shift
|
|
1387
|
+
#
|
|
1388
|
+
# pkg:gem/csv#lib/csv.rb:2803
|
|
1389
|
+
def shift; end
|
|
1390
|
+
|
|
1391
|
+
# :call-seq:
|
|
1392
|
+
# csv.skip_blanks? -> true or false
|
|
1393
|
+
#
|
|
1394
|
+
# Returns the value that determines whether blank lines are to be ignored; used for parsing;
|
|
1395
|
+
# see {Option +skip_blanks+}[#class-CSV-label-Option+skip_blanks]:
|
|
1396
|
+
# CSV.new('').skip_blanks? # => false
|
|
1397
|
+
#
|
|
1398
|
+
# pkg:gem/csv#lib/csv.rb:2296
|
|
1399
|
+
def skip_blanks?; end
|
|
1400
|
+
|
|
1401
|
+
# :call-seq:
|
|
1402
|
+
# csv.skip_lines -> regexp or nil
|
|
1403
|
+
#
|
|
1404
|
+
# Returns the \Regexp used to identify comment lines; used for parsing;
|
|
1405
|
+
# see {Option +skip_lines+}[#class-CSV-label-Option+skip_lines]:
|
|
1406
|
+
# CSV.new('').skip_lines # => nil
|
|
1407
|
+
#
|
|
1408
|
+
# pkg:gem/csv#lib/csv.rb:2198
|
|
1409
|
+
def skip_lines; end
|
|
1410
|
+
|
|
1411
|
+
# pkg:gem/csv#lib/csv.rb:2418
|
|
1412
|
+
def stat(*args); end
|
|
1413
|
+
|
|
1414
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1415
|
+
def string(*args, **_arg1, &block); end
|
|
1416
|
+
|
|
1417
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1418
|
+
def sync(*args, **_arg1, &block); end
|
|
1419
|
+
|
|
1420
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1421
|
+
def sync=(*args, **_arg1, &block); end
|
|
1422
|
+
|
|
1423
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1424
|
+
def tell(*args, **_arg1, &block); end
|
|
1425
|
+
|
|
1426
|
+
# pkg:gem/csv#lib/csv.rb:2423
|
|
1427
|
+
def to_i; end
|
|
1428
|
+
|
|
1429
|
+
# pkg:gem/csv#lib/csv.rb:2428
|
|
1430
|
+
def to_io; end
|
|
1431
|
+
|
|
1432
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1433
|
+
def truncate(*args, **_arg1, &block); end
|
|
1434
|
+
|
|
1435
|
+
# pkg:gem/csv#lib/csv.rb:2389
|
|
1436
|
+
def tty?(*args, **_arg1, &block); end
|
|
1437
|
+
|
|
1438
|
+
# :call-seq:
|
|
1439
|
+
# csv.unconverted_fields? -> object
|
|
1440
|
+
#
|
|
1441
|
+
# Returns the value that determines whether unconverted fields are to be
|
|
1442
|
+
# available; used for parsing;
|
|
1443
|
+
# see {Option +unconverted_fields+}[#class-CSV-label-Option+unconverted_fields]:
|
|
1444
|
+
# CSV.new('').unconverted_fields? # => nil
|
|
1445
|
+
#
|
|
1446
|
+
# pkg:gem/csv#lib/csv.rb:2231
|
|
1447
|
+
def unconverted_fields?; end
|
|
1448
|
+
|
|
1449
|
+
# :call-seq:
|
|
1450
|
+
# csv.write_headers? -> true or false
|
|
1451
|
+
#
|
|
1452
|
+
# Returns the value that determines whether headers are to be written; used for generating;
|
|
1453
|
+
# see {Option +write_headers+}[#class-CSV-label-Option+write_headers]:
|
|
1454
|
+
# CSV.new('').write_headers? # => nil
|
|
1455
|
+
#
|
|
1456
|
+
# pkg:gem/csv#lib/csv.rb:2269
|
|
1457
|
+
def write_headers?; end
|
|
1458
|
+
|
|
1459
|
+
private
|
|
1460
|
+
|
|
1461
|
+
# pkg:gem/csv#lib/csv.rb:2957
|
|
1462
|
+
def build_fields_converter(initial_converters, options); end
|
|
1463
|
+
|
|
1464
|
+
# pkg:gem/csv#lib/csv.rb:2939
|
|
1465
|
+
def build_header_fields_converter; end
|
|
1466
|
+
|
|
1467
|
+
# pkg:gem/csv#lib/csv.rb:2927
|
|
1468
|
+
def build_parser_fields_converter; end
|
|
1469
|
+
|
|
1470
|
+
# pkg:gem/csv#lib/csv.rb:2952
|
|
1471
|
+
def build_writer_fields_converter; end
|
|
1472
|
+
|
|
1473
|
+
# Processes +fields+ with <tt>@converters</tt>, or <tt>@header_converters</tt>
|
|
1474
|
+
# if +headers+ is passed as +true+, returning the converted field set. Any
|
|
1475
|
+
# converter that changes the field into something other than a String halts
|
|
1476
|
+
# the pipeline of conversion for that field. This is primarily an efficiency
|
|
1477
|
+
# shortcut.
|
|
1478
|
+
#
|
|
1479
|
+
# pkg:gem/csv#lib/csv.rb:2902
|
|
1480
|
+
def convert_fields(fields, headers = T.unsafe(nil)); end
|
|
1481
|
+
|
|
1482
|
+
# pkg:gem/csv#lib/csv.rb:2865
|
|
1483
|
+
def determine_encoding(encoding, internal_encoding); end
|
|
1484
|
+
|
|
1485
|
+
# pkg:gem/csv#lib/csv.rb:2935
|
|
1486
|
+
def header_fields_converter; end
|
|
1487
|
+
|
|
1488
|
+
# pkg:gem/csv#lib/csv.rb:2880
|
|
1489
|
+
def normalize_converters(converters); end
|
|
1490
|
+
|
|
1491
|
+
# pkg:gem/csv#lib/csv.rb:2965
|
|
1492
|
+
def parser; end
|
|
1493
|
+
|
|
1494
|
+
# pkg:gem/csv#lib/csv.rb:2974
|
|
1495
|
+
def parser_enumerator; end
|
|
1496
|
+
|
|
1497
|
+
# pkg:gem/csv#lib/csv.rb:2923
|
|
1498
|
+
def parser_fields_converter; end
|
|
1499
|
+
|
|
1500
|
+
# pkg:gem/csv#lib/csv.rb:2969
|
|
1501
|
+
def parser_options; end
|
|
1502
|
+
|
|
1503
|
+
# Returns the encoding of the internal IO object.
|
|
1504
|
+
#
|
|
1505
|
+
# pkg:gem/csv#lib/csv.rb:2913
|
|
1506
|
+
def raw_encoding; end
|
|
1507
|
+
|
|
1508
|
+
# pkg:gem/csv#lib/csv.rb:2978
|
|
1509
|
+
def writer; end
|
|
1510
|
+
|
|
1511
|
+
# pkg:gem/csv#lib/csv.rb:2948
|
|
1512
|
+
def writer_fields_converter; end
|
|
1513
|
+
|
|
1514
|
+
# pkg:gem/csv#lib/csv.rb:2982
|
|
1515
|
+
def writer_options; end
|
|
1516
|
+
|
|
1517
|
+
class << self
|
|
1518
|
+
# :call-seq:
|
|
1519
|
+
# filter(in_string_or_io, **options) {|row| ... } -> array_of_arrays or csv_table
|
|
1520
|
+
# filter(in_string_or_io, out_string_or_io, **options) {|row| ... } -> array_of_arrays or csv_table
|
|
1521
|
+
# filter(**options) {|row| ... } -> array_of_arrays or csv_table
|
|
1522
|
+
#
|
|
1523
|
+
# - Parses \CSV from a source (\String, \IO stream, or ARGF).
|
|
1524
|
+
# - Calls the given block with each parsed row:
|
|
1525
|
+
# - Without headers, each row is an \Array.
|
|
1526
|
+
# - With headers, each row is a CSV::Row.
|
|
1527
|
+
# - Generates \CSV to an output (\String, \IO stream, or STDOUT).
|
|
1528
|
+
# - Returns the parsed source:
|
|
1529
|
+
# - Without headers, an \Array of \Arrays.
|
|
1530
|
+
# - With headers, a CSV::Table.
|
|
1531
|
+
#
|
|
1532
|
+
# When +in_string_or_io+ is given, but not +out_string_or_io+,
|
|
1533
|
+
# parses from the given +in_string_or_io+
|
|
1534
|
+
# and generates to STDOUT.
|
|
1535
|
+
#
|
|
1536
|
+
# \String input without headers:
|
|
1537
|
+
#
|
|
1538
|
+
# in_string = "foo,0\nbar,1\nbaz,2"
|
|
1539
|
+
# CSV.filter(in_string) do |row|
|
|
1540
|
+
# row[0].upcase!
|
|
1541
|
+
# row[1] = - row[1].to_i
|
|
1542
|
+
# end # => [["FOO", 0], ["BAR", -1], ["BAZ", -2]]
|
|
1543
|
+
#
|
|
1544
|
+
# Output (to STDOUT):
|
|
1545
|
+
#
|
|
1546
|
+
# FOO,0
|
|
1547
|
+
# BAR,-1
|
|
1548
|
+
# BAZ,-2
|
|
1549
|
+
#
|
|
1550
|
+
# \String input with headers:
|
|
1551
|
+
#
|
|
1552
|
+
# in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2"
|
|
1553
|
+
# CSV.filter(in_string, headers: true) do |row|
|
|
1554
|
+
# row[0].upcase!
|
|
1555
|
+
# row[1] = - row[1].to_i
|
|
1556
|
+
# end # => #<CSV::Table mode:col_or_row row_count:4>
|
|
1557
|
+
#
|
|
1558
|
+
# Output (to STDOUT):
|
|
1559
|
+
#
|
|
1560
|
+
# Name,Value
|
|
1561
|
+
# FOO,0
|
|
1562
|
+
# BAR,-1
|
|
1563
|
+
# BAZ,-2
|
|
1564
|
+
#
|
|
1565
|
+
# \IO stream input without headers:
|
|
1566
|
+
#
|
|
1567
|
+
# File.write('t.csv', "foo,0\nbar,1\nbaz,2")
|
|
1568
|
+
# File.open('t.csv') do |in_io|
|
|
1569
|
+
# CSV.filter(in_io) do |row|
|
|
1570
|
+
# row[0].upcase!
|
|
1571
|
+
# row[1] = - row[1].to_i
|
|
1572
|
+
# end
|
|
1573
|
+
# end # => [["FOO", 0], ["BAR", -1], ["BAZ", -2]]
|
|
1574
|
+
#
|
|
1575
|
+
# Output (to STDOUT):
|
|
1576
|
+
#
|
|
1577
|
+
# FOO,0
|
|
1578
|
+
# BAR,-1
|
|
1579
|
+
# BAZ,-2
|
|
1580
|
+
#
|
|
1581
|
+
# \IO stream input with headers:
|
|
1582
|
+
#
|
|
1583
|
+
# File.write('t.csv', "Name,Value\nfoo,0\nbar,1\nbaz,2")
|
|
1584
|
+
# File.open('t.csv') do |in_io|
|
|
1585
|
+
# CSV.filter(in_io, headers: true) do |row|
|
|
1586
|
+
# row[0].upcase!
|
|
1587
|
+
# row[1] = - row[1].to_i
|
|
1588
|
+
# end
|
|
1589
|
+
# end # => #<CSV::Table mode:col_or_row row_count:4>
|
|
1590
|
+
#
|
|
1591
|
+
# Output (to STDOUT):
|
|
1592
|
+
#
|
|
1593
|
+
# Name,Value
|
|
1594
|
+
# FOO,0
|
|
1595
|
+
# BAR,-1
|
|
1596
|
+
# BAZ,-2
|
|
1597
|
+
#
|
|
1598
|
+
# When both +in_string_or_io+ and +out_string_or_io+ are given,
|
|
1599
|
+
# parses from +in_string_or_io+ and generates to +out_string_or_io+.
|
|
1600
|
+
#
|
|
1601
|
+
# \String output without headers:
|
|
1602
|
+
#
|
|
1603
|
+
# in_string = "foo,0\nbar,1\nbaz,2"
|
|
1604
|
+
# out_string = ''
|
|
1605
|
+
# CSV.filter(in_string, out_string) do |row|
|
|
1606
|
+
# row[0].upcase!
|
|
1607
|
+
# row[1] = - row[1].to_i
|
|
1608
|
+
# end # => [["FOO", 0], ["BAR", -1], ["BAZ", -2]]
|
|
1609
|
+
# out_string # => "FOO,0\nBAR,-1\nBAZ,-2\n"
|
|
1610
|
+
#
|
|
1611
|
+
# \String output with headers:
|
|
1612
|
+
#
|
|
1613
|
+
# in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2"
|
|
1614
|
+
# out_string = ''
|
|
1615
|
+
# CSV.filter(in_string, out_string, headers: true) do |row|
|
|
1616
|
+
# row[0].upcase!
|
|
1617
|
+
# row[1] = - row[1].to_i
|
|
1618
|
+
# end # => #<CSV::Table mode:col_or_row row_count:4>
|
|
1619
|
+
# out_string # => "Name,Value\nFOO,0\nBAR,-1\nBAZ,-2\n"
|
|
1620
|
+
#
|
|
1621
|
+
# \IO stream output without headers:
|
|
1622
|
+
#
|
|
1623
|
+
# in_string = "foo,0\nbar,1\nbaz,2"
|
|
1624
|
+
# File.open('t.csv', 'w') do |out_io|
|
|
1625
|
+
# CSV.filter(in_string, out_io) do |row|
|
|
1626
|
+
# row[0].upcase!
|
|
1627
|
+
# row[1] = - row[1].to_i
|
|
1628
|
+
# end
|
|
1629
|
+
# end # => [["FOO", 0], ["BAR", -1], ["BAZ", -2]]
|
|
1630
|
+
# File.read('t.csv') # => "FOO,0\nBAR,-1\nBAZ,-2\n"
|
|
1631
|
+
#
|
|
1632
|
+
# \IO stream output with headers:
|
|
1633
|
+
#
|
|
1634
|
+
# in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2"
|
|
1635
|
+
# File.open('t.csv', 'w') do |out_io|
|
|
1636
|
+
# CSV.filter(in_string, out_io, headers: true) do |row|
|
|
1637
|
+
# row[0].upcase!
|
|
1638
|
+
# row[1] = - row[1].to_i
|
|
1639
|
+
# end
|
|
1640
|
+
# end # => #<CSV::Table mode:col_or_row row_count:4>
|
|
1641
|
+
# File.read('t.csv') # => "Name,Value\nFOO,0\nBAR,-1\nBAZ,-2\n"
|
|
1642
|
+
#
|
|
1643
|
+
# When neither +in_string_or_io+ nor +out_string_or_io+ given,
|
|
1644
|
+
# parses from {ARGF}[rdoc-ref:ARGF]
|
|
1645
|
+
# and generates to STDOUT.
|
|
1646
|
+
#
|
|
1647
|
+
# Without headers:
|
|
1648
|
+
#
|
|
1649
|
+
# # Put Ruby code into a file.
|
|
1650
|
+
# ruby = <<-EOT
|
|
1651
|
+
# require 'csv'
|
|
1652
|
+
# CSV.filter do |row|
|
|
1653
|
+
# row[0].upcase!
|
|
1654
|
+
# row[1] = - row[1].to_i
|
|
1655
|
+
# end
|
|
1656
|
+
# EOT
|
|
1657
|
+
# File.write('t.rb', ruby)
|
|
1658
|
+
# # Put some CSV into a file.
|
|
1659
|
+
# File.write('t.csv', "foo,0\nbar,1\nbaz,2")
|
|
1660
|
+
# # Run the Ruby code with CSV filename as argument.
|
|
1661
|
+
# system(Gem.ruby, "t.rb", "t.csv")
|
|
1662
|
+
#
|
|
1663
|
+
# Output (to STDOUT):
|
|
1664
|
+
#
|
|
1665
|
+
# FOO,0
|
|
1666
|
+
# BAR,-1
|
|
1667
|
+
# BAZ,-2
|
|
1668
|
+
#
|
|
1669
|
+
# With headers:
|
|
1670
|
+
#
|
|
1671
|
+
# # Put Ruby code into a file.
|
|
1672
|
+
# ruby = <<-EOT
|
|
1673
|
+
# require 'csv'
|
|
1674
|
+
# CSV.filter(headers: true) do |row|
|
|
1675
|
+
# row[0].upcase!
|
|
1676
|
+
# row[1] = - row[1].to_i
|
|
1677
|
+
# end
|
|
1678
|
+
# EOT
|
|
1679
|
+
# File.write('t.rb', ruby)
|
|
1680
|
+
# # Put some CSV into a file.
|
|
1681
|
+
# File.write('t.csv', "Name,Value\nfoo,0\nbar,1\nbaz,2")
|
|
1682
|
+
# # Run the Ruby code with CSV filename as argument.
|
|
1683
|
+
# system(Gem.ruby, "t.rb", "t.csv")
|
|
1684
|
+
#
|
|
1685
|
+
# Output (to STDOUT):
|
|
1686
|
+
#
|
|
1687
|
+
# Name,Value
|
|
1688
|
+
# FOO,0
|
|
1689
|
+
# BAR,-1
|
|
1690
|
+
# BAZ,-2
|
|
1691
|
+
#
|
|
1692
|
+
# Arguments:
|
|
1693
|
+
#
|
|
1694
|
+
# * Argument +in_string_or_io+ must be a \String or an \IO stream.
|
|
1695
|
+
# * Argument +out_string_or_io+ must be a \String or an \IO stream.
|
|
1696
|
+
# * Arguments <tt>**options</tt> must be keyword options.
|
|
1697
|
+
#
|
|
1698
|
+
# - Each option defined as an {option for parsing}[#class-CSV-label-Options+for+Parsing]
|
|
1699
|
+
# is used for parsing the filter input.
|
|
1700
|
+
# - Each option defined as an {option for generating}[#class-CSV-label-Options+for+Generating]
|
|
1701
|
+
# is used for generator the filter input.
|
|
1702
|
+
#
|
|
1703
|
+
# However, there are three options that may be used for both parsing and generating:
|
|
1704
|
+
# +col_sep+, +quote_char+, and +row_sep+.
|
|
1705
|
+
#
|
|
1706
|
+
# Therefore for method +filter+ (and method +filter+ only),
|
|
1707
|
+
# there are special options that allow these parsing and generating options
|
|
1708
|
+
# to be specified separately:
|
|
1709
|
+
#
|
|
1710
|
+
# - Options +input_col_sep+ and +output_col_sep+
|
|
1711
|
+
# (and their aliases +in_col_sep+ and +out_col_sep+)
|
|
1712
|
+
# specify the column separators for parsing and generating.
|
|
1713
|
+
# - Options +input_quote_char+ and +output_quote_char+
|
|
1714
|
+
# (and their aliases +in_quote_char+ and +out_quote_char+)
|
|
1715
|
+
# specify the quote characters for parsing and generting.
|
|
1716
|
+
# - Options +input_row_sep+ and +output_row_sep+
|
|
1717
|
+
# (and their aliases +in_row_sep+ and +out_row_sep+)
|
|
1718
|
+
# specify the row separators for parsing and generating.
|
|
1719
|
+
#
|
|
1720
|
+
# Example options (for column separators):
|
|
1721
|
+
#
|
|
1722
|
+
# CSV.filter # Default for both parsing and generating.
|
|
1723
|
+
# CSV.filter(in_col_sep: ';') # ';' for parsing, default for generating.
|
|
1724
|
+
# CSV.filter(out_col_sep: '|') # Default for parsing, '|' for generating.
|
|
1725
|
+
# CSV.filter(in_col_sep: ';', out_col_sep: '|') # ';' for parsing, '|' for generating.
|
|
1726
|
+
#
|
|
1727
|
+
# Note that for a special option (e.g., +input_col_sep+)
|
|
1728
|
+
# and its corresponding "regular" option (e.g., +col_sep+),
|
|
1729
|
+
# the two are mutually overriding.
|
|
1730
|
+
#
|
|
1731
|
+
# Another example (possibly surprising):
|
|
1732
|
+
#
|
|
1733
|
+
# CSV.filter(in_col_sep: ';', col_sep: '|') # '|' for both parsing(!) and generating.
|
|
1734
|
+
#
|
|
1735
|
+
# pkg:gem/csv#lib/csv.rb:1259
|
|
1736
|
+
def filter(input = T.unsafe(nil), output = T.unsafe(nil), **options); end
|
|
1737
|
+
|
|
1738
|
+
# :call-seq:
|
|
1739
|
+
# foreach(path_or_io, mode='r', **options) {|row| ... )
|
|
1740
|
+
# foreach(path_or_io, mode='r', **options) -> new_enumerator
|
|
1741
|
+
#
|
|
1742
|
+
# Calls the block with each row read from source +path_or_io+.
|
|
1743
|
+
#
|
|
1744
|
+
# \Path input without headers:
|
|
1745
|
+
#
|
|
1746
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1747
|
+
# in_path = 't.csv'
|
|
1748
|
+
# File.write(in_path, string)
|
|
1749
|
+
# CSV.foreach(in_path) {|row| p row }
|
|
1750
|
+
#
|
|
1751
|
+
# Output:
|
|
1752
|
+
#
|
|
1753
|
+
# ["foo", "0"]
|
|
1754
|
+
# ["bar", "1"]
|
|
1755
|
+
# ["baz", "2"]
|
|
1756
|
+
#
|
|
1757
|
+
# \Path input with headers:
|
|
1758
|
+
#
|
|
1759
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
1760
|
+
# in_path = 't.csv'
|
|
1761
|
+
# File.write(in_path, string)
|
|
1762
|
+
# CSV.foreach(in_path, headers: true) {|row| p row }
|
|
1763
|
+
#
|
|
1764
|
+
# Output:
|
|
1765
|
+
#
|
|
1766
|
+
# <CSV::Row "Name":"foo" "Value":"0">
|
|
1767
|
+
# <CSV::Row "Name":"bar" "Value":"1">
|
|
1768
|
+
# <CSV::Row "Name":"baz" "Value":"2">
|
|
1769
|
+
#
|
|
1770
|
+
# \IO stream input without headers:
|
|
1771
|
+
#
|
|
1772
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1773
|
+
# path = 't.csv'
|
|
1774
|
+
# File.write(path, string)
|
|
1775
|
+
# File.open('t.csv') do |in_io|
|
|
1776
|
+
# CSV.foreach(in_io) {|row| p row }
|
|
1777
|
+
# end
|
|
1778
|
+
#
|
|
1779
|
+
# Output:
|
|
1780
|
+
#
|
|
1781
|
+
# ["foo", "0"]
|
|
1782
|
+
# ["bar", "1"]
|
|
1783
|
+
# ["baz", "2"]
|
|
1784
|
+
#
|
|
1785
|
+
# \IO stream input with headers:
|
|
1786
|
+
#
|
|
1787
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
1788
|
+
# path = 't.csv'
|
|
1789
|
+
# File.write(path, string)
|
|
1790
|
+
# File.open('t.csv') do |in_io|
|
|
1791
|
+
# CSV.foreach(in_io, headers: true) {|row| p row }
|
|
1792
|
+
# end
|
|
1793
|
+
#
|
|
1794
|
+
# Output:
|
|
1795
|
+
#
|
|
1796
|
+
# <CSV::Row "Name":"foo" "Value":"0">
|
|
1797
|
+
# <CSV::Row "Name":"bar" "Value":"1">
|
|
1798
|
+
# <CSV::Row "Name":"baz" "Value":"2">
|
|
1799
|
+
#
|
|
1800
|
+
# With no block given, returns an \Enumerator:
|
|
1801
|
+
#
|
|
1802
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
1803
|
+
# path = 't.csv'
|
|
1804
|
+
# File.write(path, string)
|
|
1805
|
+
# CSV.foreach(path) # => #<Enumerator: CSV:foreach("t.csv", "r")>
|
|
1806
|
+
#
|
|
1807
|
+
# Arguments:
|
|
1808
|
+
# * Argument +path_or_io+ must be a file path or an \IO stream.
|
|
1809
|
+
# * Argument +mode+, if given, must be a \File mode.
|
|
1810
|
+
# See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes].
|
|
1811
|
+
# * Arguments <tt>**options</tt> must be keyword options.
|
|
1812
|
+
# See {Options for Parsing}[#class-CSV-label-Options+for+Parsing].
|
|
1813
|
+
# * This method optionally accepts an additional <tt>:encoding</tt> option
|
|
1814
|
+
# that you can use to specify the Encoding of the data read from +path+ or +io+.
|
|
1815
|
+
# You must provide this unless your data is in the encoding
|
|
1816
|
+
# given by <tt>Encoding::default_external</tt>.
|
|
1817
|
+
# Parsing will use this to determine how to parse the data.
|
|
1818
|
+
# You may provide a second Encoding to
|
|
1819
|
+
# have the data transcoded as it is read. For example,
|
|
1820
|
+
# would read +UTF-32BE+ data from the file
|
|
1821
|
+
# but transcode it to +UTF-8+ before parsing.
|
|
1822
|
+
#
|
|
1823
|
+
# pkg:gem/csv#lib/csv.rb:1389
|
|
1824
|
+
def foreach(path, mode = T.unsafe(nil), **options, &block); end
|
|
1825
|
+
|
|
1826
|
+
# :call-seq:
|
|
1827
|
+
# generate(csv_string, **options) {|csv| ... }
|
|
1828
|
+
# generate(**options) {|csv| ... }
|
|
1829
|
+
#
|
|
1830
|
+
# * Argument +csv_string+, if given, must be a \String object;
|
|
1831
|
+
# defaults to a new empty \String.
|
|
1832
|
+
# * Arguments +options+, if given, should be generating options.
|
|
1833
|
+
# See {Options for Generating}[#class-CSV-label-Options+for+Generating].
|
|
1834
|
+
#
|
|
1835
|
+
# ---
|
|
1836
|
+
#
|
|
1837
|
+
# Creates a new \CSV object via <tt>CSV.new(csv_string, **options)</tt>;
|
|
1838
|
+
# calls the block with the \CSV object, which the block may modify;
|
|
1839
|
+
# returns the \String generated from the \CSV object.
|
|
1840
|
+
#
|
|
1841
|
+
# Note that a passed \String *is* modified by this method.
|
|
1842
|
+
# Pass <tt>csv_string</tt>.dup if the \String must be preserved.
|
|
1843
|
+
#
|
|
1844
|
+
# This method has one additional option: <tt>:encoding</tt>,
|
|
1845
|
+
# which sets the base Encoding for the output if no no +str+ is specified.
|
|
1846
|
+
# CSV needs this hint if you plan to output non-ASCII compatible data.
|
|
1847
|
+
#
|
|
1848
|
+
# ---
|
|
1849
|
+
#
|
|
1850
|
+
# Add lines:
|
|
1851
|
+
# input_string = "foo,0\nbar,1\nbaz,2\n"
|
|
1852
|
+
# output_string = CSV.generate(input_string) do |csv|
|
|
1853
|
+
# csv << ['bat', 3]
|
|
1854
|
+
# csv << ['bam', 4]
|
|
1855
|
+
# end
|
|
1856
|
+
# output_string # => "foo,0\nbar,1\nbaz,2\nbat,3\nbam,4\n"
|
|
1857
|
+
# input_string # => "foo,0\nbar,1\nbaz,2\nbat,3\nbam,4\n"
|
|
1858
|
+
# output_string.equal?(input_string) # => true # Same string, modified
|
|
1859
|
+
#
|
|
1860
|
+
# Add lines into new string, preserving old string:
|
|
1861
|
+
# input_string = "foo,0\nbar,1\nbaz,2\n"
|
|
1862
|
+
# output_string = CSV.generate(input_string.dup) do |csv|
|
|
1863
|
+
# csv << ['bat', 3]
|
|
1864
|
+
# csv << ['bam', 4]
|
|
1865
|
+
# end
|
|
1866
|
+
# output_string # => "foo,0\nbar,1\nbaz,2\nbat,3\nbam,4\n"
|
|
1867
|
+
# input_string # => "foo,0\nbar,1\nbaz,2\n"
|
|
1868
|
+
# output_string.equal?(input_string) # => false # Different strings
|
|
1869
|
+
#
|
|
1870
|
+
# Create lines from nothing:
|
|
1871
|
+
# output_string = CSV.generate do |csv|
|
|
1872
|
+
# csv << ['foo', 0]
|
|
1873
|
+
# csv << ['bar', 1]
|
|
1874
|
+
# csv << ['baz', 2]
|
|
1875
|
+
# end
|
|
1876
|
+
# output_string # => "foo,0\nbar,1\nbaz,2\n"
|
|
1877
|
+
#
|
|
1878
|
+
# ---
|
|
1879
|
+
#
|
|
1880
|
+
# Raises an exception if +csv_string+ is not a \String object:
|
|
1881
|
+
# # Raises TypeError (no implicit conversion of Integer into String)
|
|
1882
|
+
# CSV.generate(0)
|
|
1883
|
+
#
|
|
1884
|
+
# pkg:gem/csv#lib/csv.rb:1455
|
|
1885
|
+
def generate(str = T.unsafe(nil), **options); end
|
|
1886
|
+
|
|
1887
|
+
# :call-seq:
|
|
1888
|
+
# CSV.generate_line(ary)
|
|
1889
|
+
# CSV.generate_line(ary, **options)
|
|
1890
|
+
#
|
|
1891
|
+
# Returns the \String created by generating \CSV from +ary+
|
|
1892
|
+
# using the specified +options+.
|
|
1893
|
+
#
|
|
1894
|
+
# Argument +ary+ must be an \Array.
|
|
1895
|
+
#
|
|
1896
|
+
# Special options:
|
|
1897
|
+
# * Option <tt>:row_sep</tt> defaults to <tt>"\n"> on Ruby 3.0 or later
|
|
1898
|
+
# and <tt>$INPUT_RECORD_SEPARATOR</tt> (<tt>$/</tt>) otherwise.:
|
|
1899
|
+
# $INPUT_RECORD_SEPARATOR # => "\n"
|
|
1900
|
+
# * This method accepts an additional option, <tt>:encoding</tt>, which sets the base
|
|
1901
|
+
# Encoding for the output. This method will try to guess your Encoding from
|
|
1902
|
+
# the first non-+nil+ field in +row+, if possible, but you may need to use
|
|
1903
|
+
# this parameter as a backup plan.
|
|
1904
|
+
#
|
|
1905
|
+
# For other +options+,
|
|
1906
|
+
# see {Options for Generating}[#class-CSV-label-Options+for+Generating].
|
|
1907
|
+
#
|
|
1908
|
+
# ---
|
|
1909
|
+
#
|
|
1910
|
+
# Returns the \String generated from an \Array:
|
|
1911
|
+
# CSV.generate_line(['foo', '0']) # => "foo,0\n"
|
|
1912
|
+
#
|
|
1913
|
+
# ---
|
|
1914
|
+
#
|
|
1915
|
+
# Raises an exception if +ary+ is not an \Array:
|
|
1916
|
+
# # Raises NoMethodError (undefined method `find' for :foo:Symbol)
|
|
1917
|
+
# CSV.generate_line(:foo)
|
|
1918
|
+
#
|
|
1919
|
+
# pkg:gem/csv#lib/csv.rb:1503
|
|
1920
|
+
def generate_line(row, **options); end
|
|
1921
|
+
|
|
1922
|
+
# :call-seq:
|
|
1923
|
+
# CSV.generate_lines(rows)
|
|
1924
|
+
# CSV.generate_lines(rows, **options)
|
|
1925
|
+
#
|
|
1926
|
+
# Returns the \String created by generating \CSV from
|
|
1927
|
+
# using the specified +options+.
|
|
1928
|
+
#
|
|
1929
|
+
# Argument +rows+ must be an \Array of row. Row is \Array of \String or \CSV::Row.
|
|
1930
|
+
#
|
|
1931
|
+
# Special options:
|
|
1932
|
+
# * Option <tt>:row_sep</tt> defaults to <tt>"\n"</tt> on Ruby 3.0 or later
|
|
1933
|
+
# and <tt>$INPUT_RECORD_SEPARATOR</tt> (<tt>$/</tt>) otherwise.:
|
|
1934
|
+
# $INPUT_RECORD_SEPARATOR # => "\n"
|
|
1935
|
+
# * This method accepts an additional option, <tt>:encoding</tt>, which sets the base
|
|
1936
|
+
# Encoding for the output. This method will try to guess your Encoding from
|
|
1937
|
+
# the first non-+nil+ field in +row+, if possible, but you may need to use
|
|
1938
|
+
# this parameter as a backup plan.
|
|
1939
|
+
#
|
|
1940
|
+
# For other +options+,
|
|
1941
|
+
# see {Options for Generating}[#class-CSV-label-Options+for+Generating].
|
|
1942
|
+
#
|
|
1943
|
+
# ---
|
|
1944
|
+
#
|
|
1945
|
+
# Returns the \String generated from an
|
|
1946
|
+
# CSV.generate_lines([['foo', '0'], ['bar', '1'], ['baz', '2']]) # => "foo,0\nbar,1\nbaz,2\n"
|
|
1947
|
+
#
|
|
1948
|
+
# ---
|
|
1949
|
+
#
|
|
1950
|
+
# Raises an exception
|
|
1951
|
+
# # Raises NoMethodError (undefined method `each' for :foo:Symbol)
|
|
1952
|
+
# CSV.generate_lines(:foo)
|
|
1953
|
+
#
|
|
1954
|
+
# pkg:gem/csv#lib/csv.rb:1558
|
|
1955
|
+
def generate_lines(rows, **options); end
|
|
1956
|
+
|
|
1957
|
+
# :call-seq:
|
|
1958
|
+
# instance(string, **options)
|
|
1959
|
+
# instance(io = $stdout, **options)
|
|
1960
|
+
# instance(string, **options) {|csv| ... }
|
|
1961
|
+
# instance(io = $stdout, **options) {|csv| ... }
|
|
1962
|
+
#
|
|
1963
|
+
# Creates or retrieves cached \CSV objects.
|
|
1964
|
+
# For arguments and options, see CSV.new.
|
|
1965
|
+
#
|
|
1966
|
+
# This API is not Ractor-safe.
|
|
1967
|
+
#
|
|
1968
|
+
# ---
|
|
1969
|
+
#
|
|
1970
|
+
# With no block given, returns a \CSV object.
|
|
1971
|
+
#
|
|
1972
|
+
# The first call to +instance+ creates and caches a \CSV object:
|
|
1973
|
+
# s0 = 's0'
|
|
1974
|
+
# csv0 = CSV.instance(s0)
|
|
1975
|
+
# csv0.class # => CSV
|
|
1976
|
+
#
|
|
1977
|
+
# Subsequent calls to +instance+ with that _same_ +string+ or +io+
|
|
1978
|
+
# retrieve that same cached object:
|
|
1979
|
+
# csv1 = CSV.instance(s0)
|
|
1980
|
+
# csv1.class # => CSV
|
|
1981
|
+
# csv1.equal?(csv0) # => true # Same CSV object
|
|
1982
|
+
#
|
|
1983
|
+
# A subsequent call to +instance+ with a _different_ +string+ or +io+
|
|
1984
|
+
# creates and caches a _different_ \CSV object.
|
|
1985
|
+
# s1 = 's1'
|
|
1986
|
+
# csv2 = CSV.instance(s1)
|
|
1987
|
+
# csv2.equal?(csv0) # => false # Different CSV object
|
|
1988
|
+
#
|
|
1989
|
+
# All the cached objects remains available:
|
|
1990
|
+
# csv3 = CSV.instance(s0)
|
|
1991
|
+
# csv3.equal?(csv0) # true # Same CSV object
|
|
1992
|
+
# csv4 = CSV.instance(s1)
|
|
1993
|
+
# csv4.equal?(csv2) # true # Same CSV object
|
|
1994
|
+
#
|
|
1995
|
+
# ---
|
|
1996
|
+
#
|
|
1997
|
+
# When a block is given, calls the block with the created or retrieved
|
|
1998
|
+
# \CSV object; returns the block's return value:
|
|
1999
|
+
# CSV.instance(s0) {|csv| :foo } # => :foo
|
|
2000
|
+
#
|
|
2001
|
+
# pkg:gem/csv#lib/csv.rb:1026
|
|
2002
|
+
def instance(data = T.unsafe(nil), **options); end
|
|
2003
|
+
|
|
2004
|
+
# :call-seq:
|
|
2005
|
+
# open(path_or_io, mode = "rb", **options ) -> new_csv
|
|
2006
|
+
# open(path_or_io, mode = "rb", **options ) { |csv| ... } -> object
|
|
2007
|
+
#
|
|
2008
|
+
# possible options elements:
|
|
2009
|
+
# keyword form:
|
|
2010
|
+
# :invalid => nil # raise error on invalid byte sequence (default)
|
|
2011
|
+
# :invalid => :replace # replace invalid byte sequence
|
|
2012
|
+
# :undef => :replace # replace undefined conversion
|
|
2013
|
+
# :replace => string # replacement string ("?" or "\uFFFD" if not specified)
|
|
2014
|
+
#
|
|
2015
|
+
# * Argument +path_or_io+, must be a file path or an \IO stream.
|
|
2016
|
+
# :include: ../doc/csv/arguments/io.rdoc
|
|
2017
|
+
# * Argument +mode+, if given, must be a \File mode.
|
|
2018
|
+
# See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes].
|
|
2019
|
+
# * Arguments <tt>**options</tt> must be keyword options.
|
|
2020
|
+
# See {Options for Generating}[#class-CSV-label-Options+for+Generating].
|
|
2021
|
+
# * This method optionally accepts an additional <tt>:encoding</tt> option
|
|
2022
|
+
# that you can use to specify the Encoding of the data read from +path+ or +io+.
|
|
2023
|
+
# You must provide this unless your data is in the encoding
|
|
2024
|
+
# given by <tt>Encoding::default_external</tt>.
|
|
2025
|
+
# Parsing will use this to determine how to parse the data.
|
|
2026
|
+
# You may provide a second Encoding to
|
|
2027
|
+
# have the data transcoded as it is read. For example,
|
|
2028
|
+
# would read +UTF-32BE+ data from the file
|
|
2029
|
+
# but transcode it to +UTF-8+ before parsing.
|
|
2030
|
+
#
|
|
2031
|
+
# ---
|
|
2032
|
+
#
|
|
2033
|
+
# These examples assume prior execution of:
|
|
2034
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
2035
|
+
# path = 't.csv'
|
|
2036
|
+
# File.write(path, string)
|
|
2037
|
+
#
|
|
2038
|
+
# string_io = StringIO.new
|
|
2039
|
+
# string_io << "foo,0\nbar,1\nbaz,2\n"
|
|
2040
|
+
#
|
|
2041
|
+
# ---
|
|
2042
|
+
#
|
|
2043
|
+
# With no block given, returns a new \CSV object.
|
|
2044
|
+
#
|
|
2045
|
+
# Create a \CSV object using a file path:
|
|
2046
|
+
# csv = CSV.open(path)
|
|
2047
|
+
#
|
|
2048
|
+
# Create a \CSV object using an open \File:
|
|
2049
|
+
# csv = CSV.open(File.open(path))
|
|
2050
|
+
#
|
|
2051
|
+
# Create a \CSV object using a \StringIO:
|
|
2052
|
+
# csv = CSV.open(string_io)
|
|
2053
|
+
# ---
|
|
2054
|
+
#
|
|
2055
|
+
# With a block given, calls the block with the created \CSV object;
|
|
2056
|
+
# returns the block's return value:
|
|
2057
|
+
#
|
|
2058
|
+
# Using a file path:
|
|
2059
|
+
# csv = CSV.open(path) {|csv| p csv}
|
|
2060
|
+
# Output:
|
|
2061
|
+
#
|
|
2062
|
+
# Using an open \File:
|
|
2063
|
+
# csv = CSV.open(File.open(path)) {|csv| p csv}
|
|
2064
|
+
# Output:
|
|
2065
|
+
#
|
|
2066
|
+
# Using a \StringIO:
|
|
2067
|
+
# csv = CSV.open(string_io) {|csv| p csv}
|
|
2068
|
+
# Output:
|
|
2069
|
+
# ---
|
|
2070
|
+
#
|
|
2071
|
+
# Raises an exception if the argument is not a \String object or \IO object:
|
|
2072
|
+
# # Raises TypeError (no implicit conversion of Symbol into String)
|
|
2073
|
+
# CSV.open(:foo)
|
|
2074
|
+
#
|
|
2075
|
+
# pkg:gem/csv#lib/csv.rb:1647
|
|
2076
|
+
def open(filename_or_io, mode = T.unsafe(nil), **options); end
|
|
2077
|
+
|
|
2078
|
+
# :call-seq:
|
|
2079
|
+
# parse(string) -> array_of_arrays
|
|
2080
|
+
# parse(io) -> array_of_arrays
|
|
2081
|
+
# parse(string, headers: ..., **options) -> csv_table
|
|
2082
|
+
# parse(io, headers: ..., **options) -> csv_table
|
|
2083
|
+
# parse(string, **options) {|row| ... }
|
|
2084
|
+
# parse(io, **options) {|row| ... }
|
|
2085
|
+
#
|
|
2086
|
+
# Parses +string+ or +io+ using the specified +options+.
|
|
2087
|
+
#
|
|
2088
|
+
# - Argument +string+ should be a \String object;
|
|
2089
|
+
# it will be put into a new StringIO object positioned at the beginning.
|
|
2090
|
+
# :include: ../doc/csv/arguments/io.rdoc
|
|
2091
|
+
# - Argument +options+: see {Options for Parsing}[#class-CSV-label-Options+for+Parsing]
|
|
2092
|
+
#
|
|
2093
|
+
# ====== Without Option +headers+
|
|
2094
|
+
#
|
|
2095
|
+
# Without {option +headers+}[#class-CSV-label-Option+headers] case.
|
|
2096
|
+
#
|
|
2097
|
+
# These examples assume prior execution of:
|
|
2098
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
2099
|
+
# path = 't.csv'
|
|
2100
|
+
# File.write(path, string)
|
|
2101
|
+
#
|
|
2102
|
+
# ---
|
|
2103
|
+
#
|
|
2104
|
+
# With no block given, returns an \Array of Arrays formed from the source.
|
|
2105
|
+
#
|
|
2106
|
+
# Parse a \String:
|
|
2107
|
+
# a_of_a = CSV.parse(string)
|
|
2108
|
+
# a_of_a # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
2109
|
+
#
|
|
2110
|
+
# Parse an open \File:
|
|
2111
|
+
# a_of_a = File.open(path) do |file|
|
|
2112
|
+
# CSV.parse(file)
|
|
2113
|
+
# end
|
|
2114
|
+
# a_of_a # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
2115
|
+
#
|
|
2116
|
+
# ---
|
|
2117
|
+
#
|
|
2118
|
+
# With a block given, calls the block with each parsed row:
|
|
2119
|
+
#
|
|
2120
|
+
# Parse a \String:
|
|
2121
|
+
# CSV.parse(string) {|row| p row }
|
|
2122
|
+
#
|
|
2123
|
+
# Output:
|
|
2124
|
+
# ["foo", "0"]
|
|
2125
|
+
# ["bar", "1"]
|
|
2126
|
+
# ["baz", "2"]
|
|
2127
|
+
#
|
|
2128
|
+
# Parse an open \File:
|
|
2129
|
+
# File.open(path) do |file|
|
|
2130
|
+
# CSV.parse(file) {|row| p row }
|
|
2131
|
+
# end
|
|
2132
|
+
#
|
|
2133
|
+
# Output:
|
|
2134
|
+
# ["foo", "0"]
|
|
2135
|
+
# ["bar", "1"]
|
|
2136
|
+
# ["baz", "2"]
|
|
2137
|
+
#
|
|
2138
|
+
# ====== With Option +headers+
|
|
2139
|
+
#
|
|
2140
|
+
# With {option +headers+}[#class-CSV-label-Option+headers] case.
|
|
2141
|
+
#
|
|
2142
|
+
# These examples assume prior execution of:
|
|
2143
|
+
# string = "Name,Count\nfoo,0\nbar,1\nbaz,2\n"
|
|
2144
|
+
# path = 't.csv'
|
|
2145
|
+
# File.write(path, string)
|
|
2146
|
+
#
|
|
2147
|
+
# ---
|
|
2148
|
+
#
|
|
2149
|
+
# With no block given, returns a CSV::Table object formed from the source.
|
|
2150
|
+
#
|
|
2151
|
+
# Parse a \String:
|
|
2152
|
+
# csv_table = CSV.parse(string, headers: ['Name', 'Count'])
|
|
2153
|
+
# csv_table # => #<CSV::Table mode:col_or_row row_count:5>
|
|
2154
|
+
#
|
|
2155
|
+
# Parse an open \File:
|
|
2156
|
+
# csv_table = File.open(path) do |file|
|
|
2157
|
+
# CSV.parse(file, headers: ['Name', 'Count'])
|
|
2158
|
+
# end
|
|
2159
|
+
# csv_table # => #<CSV::Table mode:col_or_row row_count:4>
|
|
2160
|
+
#
|
|
2161
|
+
# ---
|
|
2162
|
+
#
|
|
2163
|
+
# With a block given, calls the block with each parsed row,
|
|
2164
|
+
# which has been formed into a CSV::Row object:
|
|
2165
|
+
#
|
|
2166
|
+
# Parse a \String:
|
|
2167
|
+
# CSV.parse(string, headers: ['Name', 'Count']) {|row| p row }
|
|
2168
|
+
#
|
|
2169
|
+
# Output:
|
|
2170
|
+
# # <CSV::Row "Name":"foo" "Count":"0">
|
|
2171
|
+
# # <CSV::Row "Name":"bar" "Count":"1">
|
|
2172
|
+
# # <CSV::Row "Name":"baz" "Count":"2">
|
|
2173
|
+
#
|
|
2174
|
+
# Parse an open \File:
|
|
2175
|
+
# File.open(path) do |file|
|
|
2176
|
+
# CSV.parse(file, headers: ['Name', 'Count']) {|row| p row }
|
|
2177
|
+
# end
|
|
2178
|
+
#
|
|
2179
|
+
# Output:
|
|
2180
|
+
# # <CSV::Row "Name":"foo" "Count":"0">
|
|
2181
|
+
# # <CSV::Row "Name":"bar" "Count":"1">
|
|
2182
|
+
# # <CSV::Row "Name":"baz" "Count":"2">
|
|
2183
|
+
#
|
|
2184
|
+
# ---
|
|
2185
|
+
#
|
|
2186
|
+
# Raises an exception if the argument is not a \String object or \IO object:
|
|
2187
|
+
# # Raises NoMethodError (undefined method `close' for :foo:Symbol)
|
|
2188
|
+
# CSV.parse(:foo)
|
|
2189
|
+
#
|
|
2190
|
+
# ---
|
|
2191
|
+
#
|
|
2192
|
+
# Please make sure if your text contains \BOM or not. CSV.parse will not remove
|
|
2193
|
+
# \BOM automatically. You might want to remove \BOM before calling CSV.parse :
|
|
2194
|
+
# # remove BOM on calling File.open
|
|
2195
|
+
# CSV.parse(file, headers: true) do |row|
|
|
2196
|
+
# # you can get value by column name because BOM is removed
|
|
2197
|
+
# p row['Name']
|
|
2198
|
+
# end
|
|
2199
|
+
# end
|
|
2200
|
+
#
|
|
2201
|
+
# Output:
|
|
2202
|
+
# # "foo"
|
|
2203
|
+
# # "bar"
|
|
2204
|
+
# # "baz"
|
|
2205
|
+
#
|
|
2206
|
+
# pkg:gem/csv#lib/csv.rb:1825
|
|
2207
|
+
def parse(str, **options, &block); end
|
|
2208
|
+
|
|
2209
|
+
# :call-seq:
|
|
2210
|
+
# CSV.parse_line(string) -> new_array or nil
|
|
2211
|
+
# CSV.parse_line(io) -> new_array or nil
|
|
2212
|
+
# CSV.parse_line(string, **options) -> new_array or nil
|
|
2213
|
+
# CSV.parse_line(io, **options) -> new_array or nil
|
|
2214
|
+
# CSV.parse_line(string, headers: true, **options) -> csv_row or nil
|
|
2215
|
+
# CSV.parse_line(io, headers: true, **options) -> csv_row or nil
|
|
2216
|
+
#
|
|
2217
|
+
# Returns the data created by parsing the first line of +string+ or +io+
|
|
2218
|
+
# using the specified +options+.
|
|
2219
|
+
#
|
|
2220
|
+
# - Argument +string+ should be a \String object;
|
|
2221
|
+
# it will be put into a new StringIO object positioned at the beginning.
|
|
2222
|
+
# :include: ../doc/csv/arguments/io.rdoc
|
|
2223
|
+
# - Argument +options+: see {Options for Parsing}[#class-CSV-label-Options+for+Parsing]
|
|
2224
|
+
#
|
|
2225
|
+
# ====== Without Option +headers+
|
|
2226
|
+
#
|
|
2227
|
+
# Without option +headers+, returns the first row as a new \Array.
|
|
2228
|
+
#
|
|
2229
|
+
# These examples assume prior execution of:
|
|
2230
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
2231
|
+
# path = 't.csv'
|
|
2232
|
+
# File.write(path, string)
|
|
2233
|
+
#
|
|
2234
|
+
# Parse the first line from a \String object:
|
|
2235
|
+
# CSV.parse_line(string) # => ["foo", "0"]
|
|
2236
|
+
#
|
|
2237
|
+
# Parse the first line from a File object:
|
|
2238
|
+
# File.open(path) do |file|
|
|
2239
|
+
# CSV.parse_line(file) # => ["foo", "0"]
|
|
2240
|
+
# end # => ["foo", "0"]
|
|
2241
|
+
#
|
|
2242
|
+
# Returns +nil+ if the argument is an empty \String:
|
|
2243
|
+
# CSV.parse_line('') # => nil
|
|
2244
|
+
#
|
|
2245
|
+
# ====== With Option +headers+
|
|
2246
|
+
#
|
|
2247
|
+
# With {option +headers+}[#class-CSV-label-Option+headers],
|
|
2248
|
+
# returns the first row as a CSV::Row object.
|
|
2249
|
+
#
|
|
2250
|
+
# These examples assume prior execution of:
|
|
2251
|
+
# string = "Name,Count\nfoo,0\nbar,1\nbaz,2\n"
|
|
2252
|
+
# path = 't.csv'
|
|
2253
|
+
# File.write(path, string)
|
|
2254
|
+
#
|
|
2255
|
+
# Parse the first line from a \String object:
|
|
2256
|
+
# CSV.parse_line(string, headers: true) # => #<CSV::Row "Name":"foo" "Count":"0">
|
|
2257
|
+
#
|
|
2258
|
+
# Parse the first line from a File object:
|
|
2259
|
+
# File.open(path) do |file|
|
|
2260
|
+
# CSV.parse_line(file, headers: true)
|
|
2261
|
+
# end # => #<CSV::Row "Name":"foo" "Count":"0">
|
|
2262
|
+
#
|
|
2263
|
+
# ---
|
|
2264
|
+
#
|
|
2265
|
+
# Raises an exception if the argument is +nil+:
|
|
2266
|
+
# # Raises ArgumentError (Cannot parse nil as CSV):
|
|
2267
|
+
# CSV.parse_line(nil)
|
|
2268
|
+
#
|
|
2269
|
+
# pkg:gem/csv#lib/csv.rb:1898
|
|
2270
|
+
def parse_line(line, **options); end
|
|
2271
|
+
|
|
2272
|
+
# :call-seq:
|
|
2273
|
+
# read(source, **options) -> array_of_arrays
|
|
2274
|
+
# read(source, headers: true, **options) -> csv_table
|
|
2275
|
+
#
|
|
2276
|
+
# Opens the given +source+ with the given +options+ (see CSV.open),
|
|
2277
|
+
# reads the source (see CSV#read), and returns the result,
|
|
2278
|
+
# which will be either an \Array of Arrays or a CSV::Table.
|
|
2279
|
+
#
|
|
2280
|
+
# Without headers:
|
|
2281
|
+
# string = "foo,0\nbar,1\nbaz,2\n"
|
|
2282
|
+
# path = 't.csv'
|
|
2283
|
+
# File.write(path, string)
|
|
2284
|
+
# CSV.read(path) # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
2285
|
+
#
|
|
2286
|
+
# With headers:
|
|
2287
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
2288
|
+
# path = 't.csv'
|
|
2289
|
+
# File.write(path, string)
|
|
2290
|
+
# CSV.read(path, headers: true) # => #<CSV::Table mode:col_or_row row_count:4>
|
|
2291
|
+
#
|
|
2292
|
+
# pkg:gem/csv#lib/csv.rb:1922
|
|
2293
|
+
def read(path, **options); end
|
|
2294
|
+
|
|
2295
|
+
# :call-seq:
|
|
2296
|
+
# CSV.readlines(source, **options)
|
|
2297
|
+
#
|
|
2298
|
+
# Alias for CSV.read.
|
|
2299
|
+
#
|
|
2300
|
+
# pkg:gem/csv#lib/csv.rb:1930
|
|
2301
|
+
def readlines(path, **options); end
|
|
2302
|
+
|
|
2303
|
+
# :call-seq:
|
|
2304
|
+
# CSV.table(source, **options)
|
|
2305
|
+
#
|
|
2306
|
+
# Calls CSV.read with +source+, +options+, and certain default options:
|
|
2307
|
+
# - +headers+: +true+
|
|
2308
|
+
# - +converters+: +:numeric+
|
|
2309
|
+
# - +header_converters+: +:symbol+
|
|
2310
|
+
#
|
|
2311
|
+
# Returns a CSV::Table object.
|
|
2312
|
+
#
|
|
2313
|
+
# Example:
|
|
2314
|
+
# string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
2315
|
+
# path = 't.csv'
|
|
2316
|
+
# File.write(path, string)
|
|
2317
|
+
# CSV.table(path) # => #<CSV::Table mode:col_or_row row_count:4>
|
|
2318
|
+
#
|
|
2319
|
+
# pkg:gem/csv#lib/csv.rb:1949
|
|
2320
|
+
def table(path, **options); end
|
|
2321
|
+
|
|
2322
|
+
private
|
|
2323
|
+
|
|
2324
|
+
# pkg:gem/csv#lib/csv.rb:1990
|
|
2325
|
+
def create_stringio(str, mode, opts); end
|
|
2326
|
+
|
|
2327
|
+
# pkg:gem/csv#lib/csv.rb:1963
|
|
2328
|
+
def may_enable_bom_detection_automatically(filename_or_io, mode, options, file_opts); end
|
|
2329
|
+
end
|
|
2330
|
+
end
|
|
2331
|
+
|
|
2332
|
+
# The encoding used by all converters.
|
|
2333
|
+
#
|
|
2334
|
+
# pkg:gem/csv#lib/csv.rb:895
|
|
2335
|
+
CSV::ConverterEncoding = T.let(T.unsafe(nil), Encoding)
|
|
2336
|
+
|
|
2337
|
+
# A Regexp used to find and convert some common Date formats.
|
|
2338
|
+
#
|
|
2339
|
+
# pkg:gem/csv#lib/csv.rb:884
|
|
2340
|
+
CSV::DateMatcher = T.let(T.unsafe(nil), Regexp)
|
|
2341
|
+
|
|
2342
|
+
# A Regexp used to find and convert some common (Date)Time formats.
|
|
2343
|
+
#
|
|
2344
|
+
# pkg:gem/csv#lib/csv.rb:887
|
|
2345
|
+
CSV::DateTimeMatcher = T.let(T.unsafe(nil), Regexp)
|
|
2346
|
+
|
|
2347
|
+
# A FieldInfo Struct contains details about a field's position in the data
|
|
2348
|
+
# source it was read from. CSV will pass this Struct to some blocks that make
|
|
2349
|
+
# decisions based on field structure. See CSV.convert_fields() for an
|
|
2350
|
+
# example.
|
|
2351
|
+
#
|
|
2352
|
+
# <b><tt>index</tt></b>:: The zero-based index of the field in its row.
|
|
2353
|
+
# <b><tt>line</tt></b>:: The line of the data source this row is from.
|
|
2354
|
+
# <b><tt>header</tt></b>:: The header for the column, when available.
|
|
2355
|
+
# <b><tt>quoted?</tt></b>:: True or false, whether the original value is quoted or not.
|
|
2356
|
+
#
|
|
2357
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2358
|
+
class CSV::FieldInfo < ::Struct
|
|
2359
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2360
|
+
def header; end
|
|
2361
|
+
|
|
2362
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2363
|
+
def header=(_); end
|
|
2364
|
+
|
|
2365
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2366
|
+
def index; end
|
|
2367
|
+
|
|
2368
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2369
|
+
def index=(_); end
|
|
2370
|
+
|
|
2371
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2372
|
+
def line; end
|
|
2373
|
+
|
|
2374
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2375
|
+
def line=(_); end
|
|
2376
|
+
|
|
2377
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2378
|
+
def quoted?; end
|
|
2379
|
+
|
|
2380
|
+
class << self
|
|
2381
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2382
|
+
def [](*_arg0); end
|
|
2383
|
+
|
|
2384
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2385
|
+
def inspect; end
|
|
2386
|
+
|
|
2387
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2388
|
+
def keyword_init?; end
|
|
2389
|
+
|
|
2390
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2391
|
+
def members; end
|
|
2392
|
+
|
|
2393
|
+
# pkg:gem/csv#lib/csv.rb:881
|
|
2394
|
+
def new(*_arg0); end
|
|
2395
|
+
end
|
|
2396
|
+
end
|
|
2397
|
+
|
|
2398
|
+
# Note: Don't use this class directly. This is an internal class.
|
|
2399
|
+
#
|
|
2400
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:5
|
|
2401
|
+
class CSV::FieldsConverter
|
|
2402
|
+
include ::Enumerable
|
|
2403
|
+
|
|
2404
|
+
# A CSV::FieldsConverter is a data structure for storing the
|
|
2405
|
+
# fields converter properties to be passed as a parameter
|
|
2406
|
+
# when parsing a new file (e.g. CSV::Parser.new(@io, parser_options))
|
|
2407
|
+
#
|
|
2408
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:20
|
|
2409
|
+
def initialize(options = T.unsafe(nil)); end
|
|
2410
|
+
|
|
2411
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:30
|
|
2412
|
+
def add_converter(name = T.unsafe(nil), &converter); end
|
|
2413
|
+
|
|
2414
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:54
|
|
2415
|
+
def convert(fields, headers, lineno, quoted_fields = T.unsafe(nil)); end
|
|
2416
|
+
|
|
2417
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:46
|
|
2418
|
+
def each(&block); end
|
|
2419
|
+
|
|
2420
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:50
|
|
2421
|
+
def empty?; end
|
|
2422
|
+
|
|
2423
|
+
private
|
|
2424
|
+
|
|
2425
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:92
|
|
2426
|
+
def builtin_converters; end
|
|
2427
|
+
|
|
2428
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:87
|
|
2429
|
+
def need_convert?; end
|
|
2430
|
+
|
|
2431
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:83
|
|
2432
|
+
def need_static_convert?; end
|
|
2433
|
+
end
|
|
2434
|
+
|
|
2435
|
+
# pkg:gem/csv#lib/csv/fields_converter.rb:8
|
|
2436
|
+
CSV::FieldsConverter::NO_QUOTED_FIELDS = T.let(T.unsafe(nil), Array)
|
|
2437
|
+
|
|
2438
|
+
# A \Hash containing the names and \Procs for the built-in header converters.
|
|
2439
|
+
# See {Built-In Header Converters}[#class-CSV-label-Built-In+Header+Converters].
|
|
2440
|
+
#
|
|
2441
|
+
# This \Hash is intentionally left unfrozen, and may be extended with
|
|
2442
|
+
# custom field converters.
|
|
2443
|
+
# See {Custom Header Converters}[#class-CSV-label-Custom+Header+Converters].
|
|
2444
|
+
#
|
|
2445
|
+
# pkg:gem/csv#lib/csv.rb:944
|
|
2446
|
+
CSV::HeaderConverters = T.let(T.unsafe(nil), Hash)
|
|
2447
|
+
|
|
2448
|
+
# pkg:gem/csv#lib/csv/input_record_separator.rb:5
|
|
2449
|
+
module CSV::InputRecordSeparator
|
|
2450
|
+
class << self
|
|
2451
|
+
# pkg:gem/csv#lib/csv/input_record_separator.rb:8
|
|
2452
|
+
def value; end
|
|
2453
|
+
end
|
|
2454
|
+
end
|
|
2455
|
+
|
|
2456
|
+
# The error thrown when the parser encounters invalid encoding in CSV.
|
|
2457
|
+
#
|
|
2458
|
+
# pkg:gem/csv#lib/csv.rb:862
|
|
2459
|
+
class CSV::InvalidEncodingError < ::CSV::MalformedCSVError
|
|
2460
|
+
# pkg:gem/csv#lib/csv.rb:864
|
|
2461
|
+
def initialize(encoding, line_number); end
|
|
2462
|
+
|
|
2463
|
+
# pkg:gem/csv#lib/csv.rb:863
|
|
2464
|
+
def encoding; end
|
|
2465
|
+
end
|
|
2466
|
+
|
|
2467
|
+
# The error thrown when the parser encounters illegal CSV formatting.
|
|
2468
|
+
#
|
|
2469
|
+
# pkg:gem/csv#lib/csv.rb:852
|
|
2470
|
+
class CSV::MalformedCSVError < ::RuntimeError
|
|
2471
|
+
# pkg:gem/csv#lib/csv.rb:855
|
|
2472
|
+
def initialize(message, line_number); end
|
|
2473
|
+
|
|
2474
|
+
# pkg:gem/csv#lib/csv.rb:853
|
|
2475
|
+
def line_number; end
|
|
2476
|
+
|
|
2477
|
+
# pkg:gem/csv#lib/csv.rb:854
|
|
2478
|
+
def lineno; end
|
|
2479
|
+
end
|
|
2480
|
+
|
|
2481
|
+
# Note: Don't use this class directly. This is an internal class.
|
|
2482
|
+
#
|
|
2483
|
+
# pkg:gem/csv#lib/csv/parser.rb:11
|
|
2484
|
+
class CSV::Parser
|
|
2485
|
+
# pkg:gem/csv#lib/csv/parser.rb:348
|
|
2486
|
+
def initialize(input, options); end
|
|
2487
|
+
|
|
2488
|
+
# pkg:gem/csv#lib/csv/parser.rb:356
|
|
2489
|
+
def column_separator; end
|
|
2490
|
+
|
|
2491
|
+
# pkg:gem/csv#lib/csv/parser.rb:368
|
|
2492
|
+
def field_size_limit; end
|
|
2493
|
+
|
|
2494
|
+
# pkg:gem/csv#lib/csv/parser.rb:388
|
|
2495
|
+
def header_row?; end
|
|
2496
|
+
|
|
2497
|
+
# pkg:gem/csv#lib/csv/parser.rb:384
|
|
2498
|
+
def headers; end
|
|
2499
|
+
|
|
2500
|
+
# pkg:gem/csv#lib/csv/parser.rb:400
|
|
2501
|
+
def liberal_parsing?; end
|
|
2502
|
+
|
|
2503
|
+
# pkg:gem/csv#lib/csv/parser.rb:408
|
|
2504
|
+
def line; end
|
|
2505
|
+
|
|
2506
|
+
# pkg:gem/csv#lib/csv/parser.rb:404
|
|
2507
|
+
def lineno; end
|
|
2508
|
+
|
|
2509
|
+
# pkg:gem/csv#lib/csv/parser.rb:372
|
|
2510
|
+
def max_field_size; end
|
|
2511
|
+
|
|
2512
|
+
# pkg:gem/csv#lib/csv/parser.rb:412
|
|
2513
|
+
def parse(&block); end
|
|
2514
|
+
|
|
2515
|
+
# pkg:gem/csv#lib/csv/parser.rb:364
|
|
2516
|
+
def quote_character; end
|
|
2517
|
+
|
|
2518
|
+
# pkg:gem/csv#lib/csv/parser.rb:392
|
|
2519
|
+
def return_headers?; end
|
|
2520
|
+
|
|
2521
|
+
# pkg:gem/csv#lib/csv/parser.rb:360
|
|
2522
|
+
def row_separator; end
|
|
2523
|
+
|
|
2524
|
+
# pkg:gem/csv#lib/csv/parser.rb:396
|
|
2525
|
+
def skip_blanks?; end
|
|
2526
|
+
|
|
2527
|
+
# pkg:gem/csv#lib/csv/parser.rb:376
|
|
2528
|
+
def skip_lines; end
|
|
2529
|
+
|
|
2530
|
+
# pkg:gem/csv#lib/csv/parser.rb:380
|
|
2531
|
+
def unconverted_fields?; end
|
|
2532
|
+
|
|
2533
|
+
# pkg:gem/csv#lib/csv/parser.rb:447
|
|
2534
|
+
def use_headers?; end
|
|
2535
|
+
|
|
2536
|
+
private
|
|
2537
|
+
|
|
2538
|
+
# This method injects an instance variable <tt>unconverted_fields</tt> into
|
|
2539
|
+
# +row+ and an accessor method for +row+ called unconverted_fields(). The
|
|
2540
|
+
# variable is set to the contents of +fields+.
|
|
2541
|
+
#
|
|
2542
|
+
# pkg:gem/csv#lib/csv/parser.rb:1294
|
|
2543
|
+
def add_unconverted_fields(row, fields); end
|
|
2544
|
+
|
|
2545
|
+
# pkg:gem/csv#lib/csv/parser.rb:806
|
|
2546
|
+
def adjust_headers(headers, quoted_fields); end
|
|
2547
|
+
|
|
2548
|
+
# pkg:gem/csv#lib/csv/parser.rb:881
|
|
2549
|
+
def build_scanner; end
|
|
2550
|
+
|
|
2551
|
+
# pkg:gem/csv#lib/csv/parser.rb:728
|
|
2552
|
+
def detect_row_separator(sample, cr, lf); end
|
|
2553
|
+
|
|
2554
|
+
# pkg:gem/csv#lib/csv/parser.rb:1265
|
|
2555
|
+
def emit_row(row, quoted_fields = T.unsafe(nil), &block); end
|
|
2556
|
+
|
|
2557
|
+
# pkg:gem/csv#lib/csv/parser.rb:1250
|
|
2558
|
+
def ignore_broken_line; end
|
|
2559
|
+
|
|
2560
|
+
# pkg:gem/csv#lib/csv/parser.rb:758
|
|
2561
|
+
def last_line; end
|
|
2562
|
+
|
|
2563
|
+
# pkg:gem/csv#lib/csv/parser.rb:823
|
|
2564
|
+
def may_quoted?; end
|
|
2565
|
+
|
|
2566
|
+
# pkg:gem/csv#lib/csv/parser.rb:1205
|
|
2567
|
+
def parse_column_end; end
|
|
2568
|
+
|
|
2569
|
+
# pkg:gem/csv#lib/csv/parser.rb:1105
|
|
2570
|
+
def parse_column_value; end
|
|
2571
|
+
|
|
2572
|
+
# pkg:gem/csv#lib/csv/parser.rb:792
|
|
2573
|
+
def parse_headers(row); end
|
|
2574
|
+
|
|
2575
|
+
# pkg:gem/csv#lib/csv/parser.rb:945
|
|
2576
|
+
def parse_no_quote(&block); end
|
|
2577
|
+
|
|
2578
|
+
# pkg:gem/csv#lib/csv/parser.rb:974
|
|
2579
|
+
def parse_quotable_loose(&block); end
|
|
2580
|
+
|
|
2581
|
+
# pkg:gem/csv#lib/csv/parser.rb:1035
|
|
2582
|
+
def parse_quotable_robust(&block); end
|
|
2583
|
+
|
|
2584
|
+
# pkg:gem/csv#lib/csv/parser.rb:1163
|
|
2585
|
+
def parse_quoted_column_value; end
|
|
2586
|
+
|
|
2587
|
+
# pkg:gem/csv#lib/csv/parser.rb:1219
|
|
2588
|
+
def parse_row_end; end
|
|
2589
|
+
|
|
2590
|
+
# pkg:gem/csv#lib/csv/parser.rb:1135
|
|
2591
|
+
def parse_unquoted_column_value; end
|
|
2592
|
+
|
|
2593
|
+
# A set of tasks to prepare the file in order to parse it
|
|
2594
|
+
#
|
|
2595
|
+
# pkg:gem/csv#lib/csv/parser.rb:453
|
|
2596
|
+
def prepare; end
|
|
2597
|
+
|
|
2598
|
+
# pkg:gem/csv#lib/csv/parser.rb:508
|
|
2599
|
+
def prepare_backslash; end
|
|
2600
|
+
|
|
2601
|
+
# pkg:gem/csv#lib/csv/parser.rb:766
|
|
2602
|
+
def prepare_header; end
|
|
2603
|
+
|
|
2604
|
+
# pkg:gem/csv#lib/csv/parser.rb:752
|
|
2605
|
+
def prepare_line; end
|
|
2606
|
+
|
|
2607
|
+
# pkg:gem/csv#lib/csv/parser.rb:812
|
|
2608
|
+
def prepare_parser; end
|
|
2609
|
+
|
|
2610
|
+
# pkg:gem/csv#lib/csv/parser.rb:492
|
|
2611
|
+
def prepare_quote_character; end
|
|
2612
|
+
|
|
2613
|
+
# pkg:gem/csv#lib/csv/parser.rb:648
|
|
2614
|
+
def prepare_quoted; end
|
|
2615
|
+
|
|
2616
|
+
# pkg:gem/csv#lib/csv/parser.rb:580
|
|
2617
|
+
def prepare_separators; end
|
|
2618
|
+
|
|
2619
|
+
# pkg:gem/csv#lib/csv/parser.rb:523
|
|
2620
|
+
def prepare_skip_lines; end
|
|
2621
|
+
|
|
2622
|
+
# pkg:gem/csv#lib/csv/parser.rb:540
|
|
2623
|
+
def prepare_strip; end
|
|
2624
|
+
|
|
2625
|
+
# pkg:gem/csv#lib/csv/parser.rb:675
|
|
2626
|
+
def prepare_unquoted; end
|
|
2627
|
+
|
|
2628
|
+
# pkg:gem/csv#lib/csv/parser.rb:468
|
|
2629
|
+
def prepare_variable; end
|
|
2630
|
+
|
|
2631
|
+
# pkg:gem/csv#lib/csv/parser.rb:688
|
|
2632
|
+
def resolve_row_separator(separator); end
|
|
2633
|
+
|
|
2634
|
+
# pkg:gem/csv#lib/csv/parser.rb:925
|
|
2635
|
+
def skip_line?(line); end
|
|
2636
|
+
|
|
2637
|
+
# pkg:gem/csv#lib/csv/parser.rb:908
|
|
2638
|
+
def skip_needless_lines; end
|
|
2639
|
+
|
|
2640
|
+
# pkg:gem/csv#lib/csv/parser.rb:1256
|
|
2641
|
+
def start_row; end
|
|
2642
|
+
|
|
2643
|
+
# pkg:gem/csv#lib/csv/parser.rb:1232
|
|
2644
|
+
def strip_value(value); end
|
|
2645
|
+
|
|
2646
|
+
# pkg:gem/csv#lib/csv/parser.rb:937
|
|
2647
|
+
def validate_field_size(field); end
|
|
2648
|
+
|
|
2649
|
+
# This method verifies that there are no (obvious) ambiguities with the
|
|
2650
|
+
# provided +col_sep+ and +strip+ parsing options. For example, if +col_sep+
|
|
2651
|
+
# and +strip+ were both equal to +\t+, then there would be no clear way to
|
|
2652
|
+
# parse the input.
|
|
2653
|
+
#
|
|
2654
|
+
# pkg:gem/csv#lib/csv/parser.rb:630
|
|
2655
|
+
def validate_strip_and_col_sep_options; end
|
|
2656
|
+
|
|
2657
|
+
class << self
|
|
2658
|
+
# Convenient method to check whether the give input reached EOF
|
|
2659
|
+
# or not.
|
|
2660
|
+
#
|
|
2661
|
+
# pkg:gem/csv#lib/csv/parser.rb:25
|
|
2662
|
+
def eof?(input); end
|
|
2663
|
+
end
|
|
2664
|
+
end
|
|
2665
|
+
|
|
2666
|
+
# CSV::InputsScanner receives IO inputs, encoding and the chunk_size.
|
|
2667
|
+
# It also controls the life cycle of the object with its methods +keep_start+,
|
|
2668
|
+
# +keep_end+, +keep_back+, +keep_drop+.
|
|
2669
|
+
#
|
|
2670
|
+
# CSV::InputsScanner.scan() tries to match with pattern at the current position.
|
|
2671
|
+
# If there's a match, the scanner advances the "scan pointer" and returns the matched string.
|
|
2672
|
+
# Otherwise, the scanner returns nil.
|
|
2673
|
+
#
|
|
2674
|
+
# CSV::InputsScanner.rest() returns the "rest" of the string (i.e. everything after the scan pointer).
|
|
2675
|
+
# If there is no more data (eos? = true), it returns "".
|
|
2676
|
+
#
|
|
2677
|
+
# pkg:gem/csv#lib/csv/parser.rb:99
|
|
2678
|
+
class CSV::Parser::InputsScanner
|
|
2679
|
+
# pkg:gem/csv#lib/csv/parser.rb:100
|
|
2680
|
+
def initialize(inputs, encoding, row_separator, chunk_size: T.unsafe(nil)); end
|
|
2681
|
+
|
|
2682
|
+
# pkg:gem/csv#lib/csv/parser.rb:270
|
|
2683
|
+
def check(pattern); end
|
|
2684
|
+
|
|
2685
|
+
# pkg:gem/csv#lib/csv/parser.rb:110
|
|
2686
|
+
def each_line(row_separator); end
|
|
2687
|
+
|
|
2688
|
+
# pkg:gem/csv#lib/csv/parser.rb:183
|
|
2689
|
+
def eos?; end
|
|
2690
|
+
|
|
2691
|
+
# pkg:gem/csv#lib/csv/parser.rb:210
|
|
2692
|
+
def keep_back; end
|
|
2693
|
+
|
|
2694
|
+
# pkg:gem/csv#lib/csv/parser.rb:249
|
|
2695
|
+
def keep_drop; end
|
|
2696
|
+
|
|
2697
|
+
# pkg:gem/csv#lib/csv/parser.rb:194
|
|
2698
|
+
def keep_end; end
|
|
2699
|
+
|
|
2700
|
+
# pkg:gem/csv#lib/csv/parser.rb:187
|
|
2701
|
+
def keep_start; end
|
|
2702
|
+
|
|
2703
|
+
# pkg:gem/csv#lib/csv/parser.rb:266
|
|
2704
|
+
def rest; end
|
|
2705
|
+
|
|
2706
|
+
# pkg:gem/csv#lib/csv/parser.rb:156
|
|
2707
|
+
def scan(pattern); end
|
|
2708
|
+
|
|
2709
|
+
# pkg:gem/csv#lib/csv/parser.rb:167
|
|
2710
|
+
def scan_all(pattern); end
|
|
2711
|
+
|
|
2712
|
+
private
|
|
2713
|
+
|
|
2714
|
+
# pkg:gem/csv#lib/csv/parser.rb:279
|
|
2715
|
+
def adjust_last_keep; end
|
|
2716
|
+
|
|
2717
|
+
# pkg:gem/csv#lib/csv/parser.rb:307
|
|
2718
|
+
def read_chunk; end
|
|
2719
|
+
|
|
2720
|
+
# pkg:gem/csv#lib/csv/parser.rb:275
|
|
2721
|
+
def trace(*args); end
|
|
2722
|
+
end
|
|
2723
|
+
|
|
2724
|
+
# Raised when encoding is invalid.
|
|
2725
|
+
#
|
|
2726
|
+
# pkg:gem/csv#lib/csv/parser.rb:35
|
|
2727
|
+
class CSV::Parser::InvalidEncoding < ::StandardError; end
|
|
2728
|
+
|
|
2729
|
+
# pkg:gem/csv#lib/csv/parser.rb:855
|
|
2730
|
+
CSV::Parser::SCANNER_TEST = T.let(T.unsafe(nil), FalseClass)
|
|
2731
|
+
|
|
2732
|
+
# pkg:gem/csv#lib/csv/parser.rb:577
|
|
2733
|
+
CSV::Parser::STRING_SCANNER_SCAN_ACCEPT_STRING = T.let(T.unsafe(nil), TrueClass)
|
|
2734
|
+
|
|
2735
|
+
# CSV::Scanner receives a CSV output, scans it and return the content.
|
|
2736
|
+
# It also controls the life cycle of the object with its methods +keep_start+,
|
|
2737
|
+
# +keep_end+, +keep_back+, +keep_drop+.
|
|
2738
|
+
#
|
|
2739
|
+
# Uses StringScanner (the official strscan gem). Strscan provides lexical
|
|
2740
|
+
# scanning operations on a String. We inherit its object and take advantage
|
|
2741
|
+
# on the methods. For more information, please visit:
|
|
2742
|
+
# https://docs.ruby-lang.org/en/master/StringScanner.html
|
|
2743
|
+
#
|
|
2744
|
+
# pkg:gem/csv#lib/csv/parser.rb:52
|
|
2745
|
+
class CSV::Parser::Scanner < ::StringScanner
|
|
2746
|
+
# pkg:gem/csv#lib/csv/parser.rb:55
|
|
2747
|
+
def initialize(*args); end
|
|
2748
|
+
|
|
2749
|
+
# pkg:gem/csv#lib/csv/parser.rb:60
|
|
2750
|
+
def each_line(row_separator); end
|
|
2751
|
+
|
|
2752
|
+
# pkg:gem/csv#lib/csv/parser.rb:78
|
|
2753
|
+
def keep_back; end
|
|
2754
|
+
|
|
2755
|
+
# pkg:gem/csv#lib/csv/parser.rb:82
|
|
2756
|
+
def keep_drop; end
|
|
2757
|
+
|
|
2758
|
+
# pkg:gem/csv#lib/csv/parser.rb:73
|
|
2759
|
+
def keep_end; end
|
|
2760
|
+
|
|
2761
|
+
# pkg:gem/csv#lib/csv/parser.rb:69
|
|
2762
|
+
def keep_start; end
|
|
2763
|
+
|
|
2764
|
+
# pkg:gem/csv#lib/csv/parser.rb:53
|
|
2765
|
+
def scan_all(_arg0); end
|
|
2766
|
+
end
|
|
2767
|
+
|
|
2768
|
+
# Raised when unexpected case is happen.
|
|
2769
|
+
#
|
|
2770
|
+
# pkg:gem/csv#lib/csv/parser.rb:39
|
|
2771
|
+
class CSV::Parser::UnexpectedError < ::StandardError; end
|
|
2772
|
+
|
|
2773
|
+
# pkg:gem/csv#lib/csv/parser.rb:837
|
|
2774
|
+
class CSV::Parser::UnoptimizedStringIO
|
|
2775
|
+
# pkg:gem/csv#lib/csv/parser.rb:838
|
|
2776
|
+
def initialize(string); end
|
|
2777
|
+
|
|
2778
|
+
# pkg:gem/csv#lib/csv/parser.rb:846
|
|
2779
|
+
def each_line(*args, &block); end
|
|
2780
|
+
|
|
2781
|
+
# pkg:gem/csv#lib/csv/parser.rb:850
|
|
2782
|
+
def eof?; end
|
|
2783
|
+
|
|
2784
|
+
# pkg:gem/csv#lib/csv/parser.rb:842
|
|
2785
|
+
def gets(*args); end
|
|
2786
|
+
end
|
|
2787
|
+
|
|
2788
|
+
# = \CSV::Row
|
|
2789
|
+
# A \CSV::Row instance represents a \CSV table row.
|
|
2790
|
+
# (see {class CSV}[../CSV.html]).
|
|
2791
|
+
#
|
|
2792
|
+
# The instance may have:
|
|
2793
|
+
# - Fields: each is an object, not necessarily a \String.
|
|
2794
|
+
# - Headers: each serves a key, and also need not be a \String.
|
|
2795
|
+
#
|
|
2796
|
+
# === Instance Methods
|
|
2797
|
+
#
|
|
2798
|
+
# \CSV::Row has three groups of instance methods:
|
|
2799
|
+
# - Its own internally defined instance methods.
|
|
2800
|
+
# - Methods included by module Enumerable.
|
|
2801
|
+
# - Methods delegated to class Array.:
|
|
2802
|
+
# * Array#empty?
|
|
2803
|
+
# * Array#length
|
|
2804
|
+
# * Array#size
|
|
2805
|
+
#
|
|
2806
|
+
# == Creating a \CSV::Row Instance
|
|
2807
|
+
#
|
|
2808
|
+
# Commonly, a new \CSV::Row instance is created by parsing \CSV source
|
|
2809
|
+
# that has headers:
|
|
2810
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
2811
|
+
# table = CSV.parse(source, headers: true)
|
|
2812
|
+
# table.each {|row| p row }
|
|
2813
|
+
# Output:
|
|
2814
|
+
# #<CSV::Row "Name":"foo" "Value":"0">
|
|
2815
|
+
# #<CSV::Row "Name":"bar" "Value":"1">
|
|
2816
|
+
# #<CSV::Row "Name":"baz" "Value":"2">
|
|
2817
|
+
#
|
|
2818
|
+
# You can also create a row directly. See ::new.
|
|
2819
|
+
#
|
|
2820
|
+
# == Headers
|
|
2821
|
+
#
|
|
2822
|
+
# Like a \CSV::Table, a \CSV::Row has headers.
|
|
2823
|
+
#
|
|
2824
|
+
# A \CSV::Row that was created by parsing \CSV source
|
|
2825
|
+
# inherits its headers from the table:
|
|
2826
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
2827
|
+
# table = CSV.parse(source, headers: true)
|
|
2828
|
+
# row = table.first
|
|
2829
|
+
# row.headers # => ["Name", "Value"]
|
|
2830
|
+
#
|
|
2831
|
+
# You can also create a new row with headers;
|
|
2832
|
+
# like the keys in a \Hash, the headers need not be Strings:
|
|
2833
|
+
# row = CSV::Row.new([:name, :value], ['foo', 0])
|
|
2834
|
+
# row.headers # => [:name, :value]
|
|
2835
|
+
#
|
|
2836
|
+
# The new row retains its headers even if added to a table
|
|
2837
|
+
# that has headers:
|
|
2838
|
+
# table << row # => #<CSV::Table mode:col_or_row row_count:5>
|
|
2839
|
+
# row.headers # => [:name, :value]
|
|
2840
|
+
# row[:name] # => "foo"
|
|
2841
|
+
# row['Name'] # => nil
|
|
2842
|
+
#
|
|
2843
|
+
#
|
|
2844
|
+
#
|
|
2845
|
+
# == Accessing Fields
|
|
2846
|
+
#
|
|
2847
|
+
# You may access a field in a \CSV::Row with either its \Integer index
|
|
2848
|
+
# (\Array-style) or its header (\Hash-style).
|
|
2849
|
+
#
|
|
2850
|
+
# Fetch a field using method #[]:
|
|
2851
|
+
# row = CSV::Row.new(['Name', 'Value'], ['foo', 0])
|
|
2852
|
+
# row[1] # => 0
|
|
2853
|
+
# row['Value'] # => 0
|
|
2854
|
+
#
|
|
2855
|
+
# Set a field using method #[]=:
|
|
2856
|
+
# row = CSV::Row.new(['Name', 'Value'], ['foo', 0])
|
|
2857
|
+
# row # => #<CSV::Row "Name":"foo" "Value":0>
|
|
2858
|
+
# row[0] = 'bar'
|
|
2859
|
+
# row['Value'] = 1
|
|
2860
|
+
# row # => #<CSV::Row "Name":"bar" "Value":1>
|
|
2861
|
+
#
|
|
2862
|
+
# pkg:gem/csv#lib/csv/row.rb:80
|
|
2863
|
+
class CSV::Row
|
|
2864
|
+
include ::Enumerable
|
|
2865
|
+
extend ::Forwardable
|
|
2866
|
+
|
|
2867
|
+
# :call-seq:
|
|
2868
|
+
# CSV::Row.new(headers, fields, header_row = false) -> csv_row
|
|
2869
|
+
#
|
|
2870
|
+
# Returns the new \CSV::Row instance constructed from
|
|
2871
|
+
# arguments +headers+ and +fields+; both should be Arrays;
|
|
2872
|
+
# note that the fields need not be Strings:
|
|
2873
|
+
# row = CSV::Row.new(['Name', 'Value'], ['foo', 0])
|
|
2874
|
+
# row # => #<CSV::Row "Name":"foo" "Value":0>
|
|
2875
|
+
#
|
|
2876
|
+
# If the \Array lengths are different, the shorter is +nil+-filled:
|
|
2877
|
+
# row = CSV::Row.new(['Name', 'Value', 'Date', 'Size'], ['foo', 0])
|
|
2878
|
+
# row # => #<CSV::Row "Name":"foo" "Value":0 "Date":nil "Size":nil>
|
|
2879
|
+
#
|
|
2880
|
+
# Each \CSV::Row object is either a <i>field row</i> or a <i>header row</i>;
|
|
2881
|
+
# by default, a new row is a field row; for the row created above:
|
|
2882
|
+
# row.field_row? # => true
|
|
2883
|
+
# row.header_row? # => false
|
|
2884
|
+
#
|
|
2885
|
+
# If the optional argument +header_row+ is given as +true+,
|
|
2886
|
+
# the created row is a header row:
|
|
2887
|
+
# row = CSV::Row.new(['Name', 'Value'], ['foo', 0], header_row = true)
|
|
2888
|
+
# row # => #<CSV::Row "Name":"foo" "Value":0>
|
|
2889
|
+
# row.field_row? # => false
|
|
2890
|
+
# row.header_row? # => true
|
|
2891
|
+
#
|
|
2892
|
+
# pkg:gem/csv#lib/csv/row.rb:105
|
|
2893
|
+
def initialize(headers, fields, header_row = T.unsafe(nil)); end
|
|
2894
|
+
|
|
2895
|
+
# :call-seq:
|
|
2896
|
+
# row << [header, value] -> self
|
|
2897
|
+
# row << hash -> self
|
|
2898
|
+
# row << value -> self
|
|
2899
|
+
#
|
|
2900
|
+
# Adds a field to +self+; returns +self+:
|
|
2901
|
+
#
|
|
2902
|
+
# If the argument is a 2-element \Array <tt>[header, value]</tt>,
|
|
2903
|
+
# a field is added with the given +header+ and +value+:
|
|
2904
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
2905
|
+
# table = CSV.parse(source, headers: true)
|
|
2906
|
+
# row = table[0]
|
|
2907
|
+
# row << ['NAME', 'Bat']
|
|
2908
|
+
# row # => #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":"Baz" "NAME":"Bat">
|
|
2909
|
+
#
|
|
2910
|
+
# If the argument is a \Hash, each <tt>key-value</tt> pair is added
|
|
2911
|
+
# as a field with header +key+ and value +value+.
|
|
2912
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
2913
|
+
# table = CSV.parse(source, headers: true)
|
|
2914
|
+
# row = table[0]
|
|
2915
|
+
# row << {NAME: 'Bat', name: 'Bam'}
|
|
2916
|
+
# row # => #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":"Baz" NAME:"Bat" name:"Bam">
|
|
2917
|
+
#
|
|
2918
|
+
# Otherwise, the given +value+ is added as a field with no header.
|
|
2919
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
2920
|
+
# table = CSV.parse(source, headers: true)
|
|
2921
|
+
# row = table[0]
|
|
2922
|
+
# row << 'Bag'
|
|
2923
|
+
# row # => #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":"Baz" nil:"Bag">
|
|
2924
|
+
#
|
|
2925
|
+
# pkg:gem/csv#lib/csv/row.rb:389
|
|
2926
|
+
def <<(arg); end
|
|
2927
|
+
|
|
2928
|
+
# :call-seq:
|
|
2929
|
+
# row == other -> true or false
|
|
2930
|
+
#
|
|
2931
|
+
# Returns +true+ if +other+ is a /CSV::Row that has the same
|
|
2932
|
+
# fields (headers and values) in the same order as +self+;
|
|
2933
|
+
# otherwise returns +false+:
|
|
2934
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
2935
|
+
# table = CSV.parse(source, headers: true)
|
|
2936
|
+
# row = table[0]
|
|
2937
|
+
# other_row = table[0]
|
|
2938
|
+
# row == other_row # => true
|
|
2939
|
+
# other_row = table[1]
|
|
2940
|
+
# row == other_row # => false
|
|
2941
|
+
#
|
|
2942
|
+
# pkg:gem/csv#lib/csv/row.rb:633
|
|
2943
|
+
def ==(other); end
|
|
2944
|
+
|
|
2945
|
+
# pkg:gem/csv#lib/csv/row.rb:215
|
|
2946
|
+
def [](header_or_index, minimum_index = T.unsafe(nil)); end
|
|
2947
|
+
|
|
2948
|
+
# :call-seq:
|
|
2949
|
+
# row[index] = value -> value
|
|
2950
|
+
# row[header, offset] = value -> value
|
|
2951
|
+
# row[header] = value -> value
|
|
2952
|
+
#
|
|
2953
|
+
# Assigns the field value for the given +index+ or +header+;
|
|
2954
|
+
# returns +value+.
|
|
2955
|
+
#
|
|
2956
|
+
# ---
|
|
2957
|
+
#
|
|
2958
|
+
# Assign field value by \Integer index:
|
|
2959
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
2960
|
+
# table = CSV.parse(source, headers: true)
|
|
2961
|
+
# row = table[0]
|
|
2962
|
+
# row[0] = 'Bat'
|
|
2963
|
+
# row[1] = 3
|
|
2964
|
+
# row # => #<CSV::Row "Name":"Bat" "Value":3>
|
|
2965
|
+
#
|
|
2966
|
+
# Counts backward from the last column if +index+ is negative:
|
|
2967
|
+
# row[-1] = 4
|
|
2968
|
+
# row[-2] = 'Bam'
|
|
2969
|
+
# row # => #<CSV::Row "Name":"Bam" "Value":4>
|
|
2970
|
+
#
|
|
2971
|
+
# Extends the row with <tt>nil:nil</tt> if positive +index+ is not in the row:
|
|
2972
|
+
# row[4] = 5
|
|
2973
|
+
# row # => #<CSV::Row "Name":"bad" "Value":4 nil:nil nil:nil nil:5>
|
|
2974
|
+
#
|
|
2975
|
+
# Raises IndexError if negative +index+ is too small (too far from zero).
|
|
2976
|
+
#
|
|
2977
|
+
# ---
|
|
2978
|
+
#
|
|
2979
|
+
# Assign field value by header (first found):
|
|
2980
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
2981
|
+
# table = CSV.parse(source, headers: true)
|
|
2982
|
+
# row = table[0]
|
|
2983
|
+
# row['Name'] = 'Bat'
|
|
2984
|
+
# row # => #<CSV::Row "Name":"Bat" "Name":"Bar" "Name":"Baz">
|
|
2985
|
+
#
|
|
2986
|
+
# Assign field value by header, ignoring +offset+ leading fields:
|
|
2987
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
2988
|
+
# table = CSV.parse(source, headers: true)
|
|
2989
|
+
# row = table[0]
|
|
2990
|
+
# row['Name', 2] = 4
|
|
2991
|
+
# row # => #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":4>
|
|
2992
|
+
#
|
|
2993
|
+
# Append new field by (new) header:
|
|
2994
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
2995
|
+
# table = CSV.parse(source, headers: true)
|
|
2996
|
+
# row = table[0]
|
|
2997
|
+
# row['New'] = 6
|
|
2998
|
+
# row# => #<CSV::Row "Name":"foo" "Value":"0" "New":6>
|
|
2999
|
+
#
|
|
3000
|
+
# pkg:gem/csv#lib/csv/row.rb:339
|
|
3001
|
+
def []=(*args); end
|
|
3002
|
+
|
|
3003
|
+
# :call-seq:
|
|
3004
|
+
# row.deconstruct -> array
|
|
3005
|
+
#
|
|
3006
|
+
# Returns the new \Array suitable for pattern matching containing the values
|
|
3007
|
+
# of the row.
|
|
3008
|
+
#
|
|
3009
|
+
# pkg:gem/csv#lib/csv/row.rb:682
|
|
3010
|
+
def deconstruct; end
|
|
3011
|
+
|
|
3012
|
+
# :call-seq:
|
|
3013
|
+
# row.deconstruct_keys(keys) -> hash
|
|
3014
|
+
#
|
|
3015
|
+
# Returns the new \Hash suitable for pattern matching containing only the
|
|
3016
|
+
# keys specified as an argument.
|
|
3017
|
+
#
|
|
3018
|
+
# pkg:gem/csv#lib/csv/row.rb:667
|
|
3019
|
+
def deconstruct_keys(keys); end
|
|
3020
|
+
|
|
3021
|
+
# :call-seq:
|
|
3022
|
+
# delete(index) -> [header, value] or nil
|
|
3023
|
+
# delete(header) -> [header, value] or empty_array
|
|
3024
|
+
# delete(header, offset) -> [header, value] or empty_array
|
|
3025
|
+
#
|
|
3026
|
+
# Removes a specified field from +self+; returns the 2-element \Array
|
|
3027
|
+
# <tt>[header, value]</tt> if the field exists.
|
|
3028
|
+
#
|
|
3029
|
+
# If an \Integer argument +index+ is given,
|
|
3030
|
+
# removes and returns the field at offset +index+,
|
|
3031
|
+
# or returns +nil+ if the field does not exist:
|
|
3032
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3033
|
+
# table = CSV.parse(source, headers: true)
|
|
3034
|
+
# row = table[0]
|
|
3035
|
+
# row.delete(1) # => ["Name", "Bar"]
|
|
3036
|
+
# row.delete(50) # => nil
|
|
3037
|
+
#
|
|
3038
|
+
# Otherwise, if the single argument +header+ is given,
|
|
3039
|
+
# removes and returns the first-found field with the given header,
|
|
3040
|
+
# of returns a new empty \Array if the field does not exist:
|
|
3041
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3042
|
+
# table = CSV.parse(source, headers: true)
|
|
3043
|
+
# row = table[0]
|
|
3044
|
+
# row.delete('Name') # => ["Name", "Foo"]
|
|
3045
|
+
# row.delete('NAME') # => []
|
|
3046
|
+
#
|
|
3047
|
+
# If argument +header+ and \Integer argument +offset+ are given,
|
|
3048
|
+
# removes and returns the first-found field with the given header
|
|
3049
|
+
# whose +index+ is at least as large as +offset+:
|
|
3050
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3051
|
+
# table = CSV.parse(source, headers: true)
|
|
3052
|
+
# row = table[0]
|
|
3053
|
+
# row.delete('Name', 1) # => ["Name", "Bar"]
|
|
3054
|
+
# row.delete('NAME', 1) # => []
|
|
3055
|
+
#
|
|
3056
|
+
# pkg:gem/csv#lib/csv/row.rb:451
|
|
3057
|
+
def delete(header_or_index, minimum_index = T.unsafe(nil)); end
|
|
3058
|
+
|
|
3059
|
+
# :call-seq:
|
|
3060
|
+
# row.delete_if {|header, value| ... } -> self
|
|
3061
|
+
#
|
|
3062
|
+
# Removes fields from +self+ as selected by the block; returns +self+.
|
|
3063
|
+
#
|
|
3064
|
+
# Removes each field for which the block returns a truthy value:
|
|
3065
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3066
|
+
# table = CSV.parse(source, headers: true)
|
|
3067
|
+
# row = table[0]
|
|
3068
|
+
# row.delete_if {|header, value| value.start_with?('B') } # => true
|
|
3069
|
+
# row # => #<CSV::Row "Name":"Foo">
|
|
3070
|
+
# row.delete_if {|header, value| header.start_with?('B') } # => false
|
|
3071
|
+
#
|
|
3072
|
+
# If no block is given, returns a new Enumerator:
|
|
3073
|
+
# row.delete_if # => #<Enumerator: #<CSV::Row "Name":"Foo">:delete_if>
|
|
3074
|
+
#
|
|
3075
|
+
# pkg:gem/csv#lib/csv/row.rb:476
|
|
3076
|
+
def delete_if(&block); end
|
|
3077
|
+
|
|
3078
|
+
# :call-seq:
|
|
3079
|
+
# row.dig(index_or_header, *identifiers) -> object
|
|
3080
|
+
#
|
|
3081
|
+
# Finds and returns the object in nested object that is specified
|
|
3082
|
+
# by +index_or_header+ and +specifiers+.
|
|
3083
|
+
#
|
|
3084
|
+
# The nested objects may be instances of various classes.
|
|
3085
|
+
# See {Dig Methods}[rdoc-ref:dig_methods.rdoc].
|
|
3086
|
+
#
|
|
3087
|
+
# Examples:
|
|
3088
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3089
|
+
# table = CSV.parse(source, headers: true)
|
|
3090
|
+
# row = table[0]
|
|
3091
|
+
# row.dig(1) # => "0"
|
|
3092
|
+
# row.dig('Value') # => "0"
|
|
3093
|
+
# row.dig(5) # => nil
|
|
3094
|
+
#
|
|
3095
|
+
# pkg:gem/csv#lib/csv/row.rb:715
|
|
3096
|
+
def dig(index_or_header, *indexes); end
|
|
3097
|
+
|
|
3098
|
+
# :call-seq:
|
|
3099
|
+
# row.each {|header, value| ... } -> self
|
|
3100
|
+
#
|
|
3101
|
+
# Calls the block with each header-value pair; returns +self+:
|
|
3102
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3103
|
+
# table = CSV.parse(source, headers: true)
|
|
3104
|
+
# row = table[0]
|
|
3105
|
+
# row.each {|header, value| p [header, value] }
|
|
3106
|
+
# Output:
|
|
3107
|
+
# ["Name", "Foo"]
|
|
3108
|
+
# ["Name", "Bar"]
|
|
3109
|
+
# ["Name", "Baz"]
|
|
3110
|
+
#
|
|
3111
|
+
# If no block is given, returns a new Enumerator:
|
|
3112
|
+
# row.each # => #<Enumerator: #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":"Baz">:each>
|
|
3113
|
+
#
|
|
3114
|
+
# pkg:gem/csv#lib/csv/row.rb:610
|
|
3115
|
+
def each(&block); end
|
|
3116
|
+
|
|
3117
|
+
# pkg:gem/csv#lib/csv/row.rb:618
|
|
3118
|
+
def each_pair(&block); end
|
|
3119
|
+
|
|
3120
|
+
# pkg:gem/csv#lib/csv/row.rb:124
|
|
3121
|
+
def empty?(*args, **_arg1, &block); end
|
|
3122
|
+
|
|
3123
|
+
# :call-seq:
|
|
3124
|
+
# fetch(header) -> value
|
|
3125
|
+
# fetch(header, default) -> value
|
|
3126
|
+
# fetch(header) {|row| ... } -> value
|
|
3127
|
+
#
|
|
3128
|
+
# Returns the field value as specified by +header+.
|
|
3129
|
+
#
|
|
3130
|
+
# ---
|
|
3131
|
+
#
|
|
3132
|
+
# With the single argument +header+, returns the field value
|
|
3133
|
+
# for that header (first found):
|
|
3134
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3135
|
+
# table = CSV.parse(source, headers: true)
|
|
3136
|
+
# row = table[0]
|
|
3137
|
+
# row.fetch('Name') # => "Foo"
|
|
3138
|
+
#
|
|
3139
|
+
# Raises exception +KeyError+ if the header does not exist.
|
|
3140
|
+
#
|
|
3141
|
+
# ---
|
|
3142
|
+
#
|
|
3143
|
+
# With arguments +header+ and +default+ given,
|
|
3144
|
+
# returns the field value for the header (first found)
|
|
3145
|
+
# if the header exists, otherwise returns +default+:
|
|
3146
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3147
|
+
# table = CSV.parse(source, headers: true)
|
|
3148
|
+
# row = table[0]
|
|
3149
|
+
# row.fetch('Name', '') # => "Foo"
|
|
3150
|
+
# row.fetch(:nosuch, '') # => ""
|
|
3151
|
+
#
|
|
3152
|
+
# ---
|
|
3153
|
+
#
|
|
3154
|
+
# With argument +header+ and a block given,
|
|
3155
|
+
# returns the field value for the header (first found)
|
|
3156
|
+
# if the header exists; otherwise calls the block
|
|
3157
|
+
# and returns its return value:
|
|
3158
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3159
|
+
# table = CSV.parse(source, headers: true)
|
|
3160
|
+
# row = table[0]
|
|
3161
|
+
# row.fetch('Name') {|header| fail 'Cannot happen' } # => "Foo"
|
|
3162
|
+
# row.fetch(:nosuch) {|header| "Header '#{header} not found'" } # => "Header 'nosuch not found'"
|
|
3163
|
+
#
|
|
3164
|
+
# pkg:gem/csv#lib/csv/row.rb:258
|
|
3165
|
+
def fetch(header, *varargs); end
|
|
3166
|
+
|
|
3167
|
+
# :call-seq:
|
|
3168
|
+
# field(index) -> value
|
|
3169
|
+
# field(header) -> value
|
|
3170
|
+
# field(header, offset) -> value
|
|
3171
|
+
#
|
|
3172
|
+
# Returns the field value for the given +index+ or +header+.
|
|
3173
|
+
#
|
|
3174
|
+
# ---
|
|
3175
|
+
#
|
|
3176
|
+
# Fetch field value by \Integer index:
|
|
3177
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3178
|
+
# table = CSV.parse(source, headers: true)
|
|
3179
|
+
# row = table[0]
|
|
3180
|
+
# row.field(0) # => "foo"
|
|
3181
|
+
# row.field(1) # => "bar"
|
|
3182
|
+
#
|
|
3183
|
+
# Counts backward from the last column if +index+ is negative:
|
|
3184
|
+
# row.field(-1) # => "0"
|
|
3185
|
+
# row.field(-2) # => "foo"
|
|
3186
|
+
#
|
|
3187
|
+
# Returns +nil+ if +index+ is out of range:
|
|
3188
|
+
# row.field(2) # => nil
|
|
3189
|
+
# row.field(-3) # => nil
|
|
3190
|
+
#
|
|
3191
|
+
# ---
|
|
3192
|
+
#
|
|
3193
|
+
# Fetch field value by header (first found):
|
|
3194
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3195
|
+
# table = CSV.parse(source, headers: true)
|
|
3196
|
+
# row = table[0]
|
|
3197
|
+
# row.field('Name') # => "Foo"
|
|
3198
|
+
#
|
|
3199
|
+
# Fetch field value by header, ignoring +offset+ leading fields:
|
|
3200
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3201
|
+
# table = CSV.parse(source, headers: true)
|
|
3202
|
+
# row = table[0]
|
|
3203
|
+
# row.field('Name', 2) # => "Baz"
|
|
3204
|
+
#
|
|
3205
|
+
# Returns +nil+ if the header does not exist.
|
|
3206
|
+
#
|
|
3207
|
+
# pkg:gem/csv#lib/csv/row.rb:203
|
|
3208
|
+
def field(header_or_index, minimum_index = T.unsafe(nil)); end
|
|
3209
|
+
|
|
3210
|
+
# :call-seq:
|
|
3211
|
+
# row.field?(value) -> true or false
|
|
3212
|
+
#
|
|
3213
|
+
# Returns +true+ if +value+ is a field in this row, +false+ otherwise:
|
|
3214
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3215
|
+
# table = CSV.parse(source, headers: true)
|
|
3216
|
+
# row = table[0]
|
|
3217
|
+
# row.field?('Bar') # => true
|
|
3218
|
+
# row.field?('BAR') # => false
|
|
3219
|
+
#
|
|
3220
|
+
# pkg:gem/csv#lib/csv/row.rb:589
|
|
3221
|
+
def field?(data); end
|
|
3222
|
+
|
|
3223
|
+
# :call-seq:
|
|
3224
|
+
# row.field_row? -> true or false
|
|
3225
|
+
#
|
|
3226
|
+
# Returns +true+ if this is a field row, +false+ otherwise.
|
|
3227
|
+
#
|
|
3228
|
+
# pkg:gem/csv#lib/csv/row.rb:148
|
|
3229
|
+
def field_row?; end
|
|
3230
|
+
|
|
3231
|
+
# :call-seq:
|
|
3232
|
+
# self.fields(*specifiers) -> array_of_fields
|
|
3233
|
+
#
|
|
3234
|
+
# Returns field values per the given +specifiers+, which may be any mixture of:
|
|
3235
|
+
# - \Integer index.
|
|
3236
|
+
# - \Range of \Integer indexes.
|
|
3237
|
+
# - 2-element \Array containing a header and offset.
|
|
3238
|
+
# - Header.
|
|
3239
|
+
# - \Range of headers.
|
|
3240
|
+
#
|
|
3241
|
+
# For +specifier+ in one of the first four cases above,
|
|
3242
|
+
# returns the result of <tt>self.field(specifier)</tt>; see #field.
|
|
3243
|
+
#
|
|
3244
|
+
# Although there may be any number of +specifiers+,
|
|
3245
|
+
# the examples here will illustrate one at a time.
|
|
3246
|
+
#
|
|
3247
|
+
# When the specifier is an \Integer +index+,
|
|
3248
|
+
# returns <tt>self.field(index)</tt>L
|
|
3249
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3250
|
+
# table = CSV.parse(source, headers: true)
|
|
3251
|
+
# row = table[0]
|
|
3252
|
+
# row.fields(1) # => ["Bar"]
|
|
3253
|
+
#
|
|
3254
|
+
# When the specifier is a \Range of \Integers +range+,
|
|
3255
|
+
# returns <tt>self.field(range)</tt>:
|
|
3256
|
+
# row.fields(1..2) # => ["Bar", "Baz"]
|
|
3257
|
+
#
|
|
3258
|
+
# When the specifier is a 2-element \Array +array+,
|
|
3259
|
+
# returns <tt>self.field(array)</tt>L
|
|
3260
|
+
# row.fields('Name', 1) # => ["Foo", "Bar"]
|
|
3261
|
+
#
|
|
3262
|
+
# When the specifier is a header +header+,
|
|
3263
|
+
# returns <tt>self.field(header)</tt>L
|
|
3264
|
+
# row.fields('Name') # => ["Foo"]
|
|
3265
|
+
#
|
|
3266
|
+
# When the specifier is a \Range of headers +range+,
|
|
3267
|
+
# forms a new \Range +new_range+ from the indexes of
|
|
3268
|
+
# <tt>range.start</tt> and <tt>range.end</tt>,
|
|
3269
|
+
# and returns <tt>self.field(new_range)</tt>:
|
|
3270
|
+
# source = "Name,NAME,name\nFoo,Bar,Baz\n"
|
|
3271
|
+
# table = CSV.parse(source, headers: true)
|
|
3272
|
+
# row = table[0]
|
|
3273
|
+
# row.fields('Name'..'NAME') # => ["Foo", "Bar"]
|
|
3274
|
+
#
|
|
3275
|
+
# Returns all fields if no argument given:
|
|
3276
|
+
# row.fields # => ["Foo", "Bar", "Baz"]
|
|
3277
|
+
#
|
|
3278
|
+
# pkg:gem/csv#lib/csv/row.rb:530
|
|
3279
|
+
def fields(*headers_and_or_indices); end
|
|
3280
|
+
|
|
3281
|
+
# :call-seq:
|
|
3282
|
+
# row.has_key?(header) -> true or false
|
|
3283
|
+
#
|
|
3284
|
+
# Returns +true+ if there is a field with the given +header+,
|
|
3285
|
+
# +false+ otherwise.
|
|
3286
|
+
#
|
|
3287
|
+
# pkg:gem/csv#lib/csv/row.rb:279
|
|
3288
|
+
def has_key?(header); end
|
|
3289
|
+
|
|
3290
|
+
# pkg:gem/csv#lib/csv/row.rb:285
|
|
3291
|
+
def header?(header); end
|
|
3292
|
+
|
|
3293
|
+
# :call-seq:
|
|
3294
|
+
# row.header_row? -> true or false
|
|
3295
|
+
#
|
|
3296
|
+
# Returns +true+ if this is a header row, +false+ otherwise.
|
|
3297
|
+
#
|
|
3298
|
+
# pkg:gem/csv#lib/csv/row.rb:140
|
|
3299
|
+
def header_row?; end
|
|
3300
|
+
|
|
3301
|
+
# :call-seq:
|
|
3302
|
+
# row.headers -> array_of_headers
|
|
3303
|
+
#
|
|
3304
|
+
# Returns the headers for this row:
|
|
3305
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3306
|
+
# table = CSV.parse(source, headers: true)
|
|
3307
|
+
# row = table.first
|
|
3308
|
+
# row.headers # => ["Name", "Value"]
|
|
3309
|
+
#
|
|
3310
|
+
# pkg:gem/csv#lib/csv/row.rb:160
|
|
3311
|
+
def headers; end
|
|
3312
|
+
|
|
3313
|
+
# pkg:gem/csv#lib/csv/row.rb:282
|
|
3314
|
+
def include?(header); end
|
|
3315
|
+
|
|
3316
|
+
# :call-seq:
|
|
3317
|
+
# index(header) -> index
|
|
3318
|
+
# index(header, offset) -> index
|
|
3319
|
+
#
|
|
3320
|
+
# Returns the index for the given header, if it exists;
|
|
3321
|
+
# otherwise returns +nil+.
|
|
3322
|
+
#
|
|
3323
|
+
# With the single argument +header+, returns the index
|
|
3324
|
+
# of the first-found field with the given +header+:
|
|
3325
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3326
|
+
# table = CSV.parse(source, headers: true)
|
|
3327
|
+
# row = table[0]
|
|
3328
|
+
# row.index('Name') # => 0
|
|
3329
|
+
# row.index('NAME') # => nil
|
|
3330
|
+
#
|
|
3331
|
+
# With arguments +header+ and +offset+,
|
|
3332
|
+
# returns the index of the first-found field with given +header+,
|
|
3333
|
+
# but ignoring the first +offset+ fields:
|
|
3334
|
+
# row.index('Name', 1) # => 1
|
|
3335
|
+
# row.index('Name', 3) # => nil
|
|
3336
|
+
#
|
|
3337
|
+
# pkg:gem/csv#lib/csv/row.rb:573
|
|
3338
|
+
def index(header, minimum_index = T.unsafe(nil)); end
|
|
3339
|
+
|
|
3340
|
+
# :call-seq:
|
|
3341
|
+
# row.inspect -> string
|
|
3342
|
+
#
|
|
3343
|
+
# Returns an ASCII-compatible \String showing:
|
|
3344
|
+
# - Class \CSV::Row.
|
|
3345
|
+
# - Header-value pairs.
|
|
3346
|
+
# Example:
|
|
3347
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3348
|
+
# table = CSV.parse(source, headers: true)
|
|
3349
|
+
# row = table[0]
|
|
3350
|
+
# row.inspect # => "#<CSV::Row \"Name\":\"foo\" \"Value\":\"0\">"
|
|
3351
|
+
#
|
|
3352
|
+
# pkg:gem/csv#lib/csv/row.rb:740
|
|
3353
|
+
def inspect; end
|
|
3354
|
+
|
|
3355
|
+
# pkg:gem/csv#lib/csv/row.rb:283
|
|
3356
|
+
def key?(header); end
|
|
3357
|
+
|
|
3358
|
+
# pkg:gem/csv#lib/csv/row.rb:124
|
|
3359
|
+
def length(*args, **_arg1, &block); end
|
|
3360
|
+
|
|
3361
|
+
# pkg:gem/csv#lib/csv/row.rb:284
|
|
3362
|
+
def member?(header); end
|
|
3363
|
+
|
|
3364
|
+
# :call-seq:
|
|
3365
|
+
# row.push(*values) -> self
|
|
3366
|
+
#
|
|
3367
|
+
# Appends each of the given +values+ to +self+ as a field; returns +self+:
|
|
3368
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3369
|
+
# table = CSV.parse(source, headers: true)
|
|
3370
|
+
# row = table[0]
|
|
3371
|
+
# row.push('Bat', 'Bam')
|
|
3372
|
+
# row # => #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":"Baz" nil:"Bat" nil:"Bam">
|
|
3373
|
+
#
|
|
3374
|
+
# pkg:gem/csv#lib/csv/row.rb:410
|
|
3375
|
+
def push(*args); end
|
|
3376
|
+
|
|
3377
|
+
# pkg:gem/csv#lib/csv/row.rb:124
|
|
3378
|
+
def size(*args, **_arg1, &block); end
|
|
3379
|
+
|
|
3380
|
+
# pkg:gem/csv#lib/csv/row.rb:675
|
|
3381
|
+
def to_ary(*_arg0); end
|
|
3382
|
+
|
|
3383
|
+
# :call-seq:
|
|
3384
|
+
# row.to_csv -> csv_string
|
|
3385
|
+
#
|
|
3386
|
+
# Returns the row as a \CSV String. Headers are not included:
|
|
3387
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3388
|
+
# table = CSV.parse(source, headers: true)
|
|
3389
|
+
# row = table[0]
|
|
3390
|
+
# row.to_csv # => "foo,0\n"
|
|
3391
|
+
#
|
|
3392
|
+
# pkg:gem/csv#lib/csv/row.rb:694
|
|
3393
|
+
def to_csv(**options); end
|
|
3394
|
+
|
|
3395
|
+
# :call-seq:
|
|
3396
|
+
# row.to_h -> hash
|
|
3397
|
+
#
|
|
3398
|
+
# Returns the new \Hash formed by adding each header-value pair in +self+
|
|
3399
|
+
# as a key-value pair in the \Hash.
|
|
3400
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3401
|
+
# table = CSV.parse(source, headers: true)
|
|
3402
|
+
# row = table[0]
|
|
3403
|
+
# row.to_h # => {"Name"=>"foo", "Value"=>"0"}
|
|
3404
|
+
#
|
|
3405
|
+
# Header order is preserved, but repeated headers are ignored:
|
|
3406
|
+
# source = "Name,Name,Name\nFoo,Bar,Baz\n"
|
|
3407
|
+
# table = CSV.parse(source, headers: true)
|
|
3408
|
+
# row = table[0]
|
|
3409
|
+
# row.to_h # => {"Name"=>"Foo"}
|
|
3410
|
+
#
|
|
3411
|
+
# pkg:gem/csv#lib/csv/row.rb:653
|
|
3412
|
+
def to_h; end
|
|
3413
|
+
|
|
3414
|
+
# pkg:gem/csv#lib/csv/row.rb:660
|
|
3415
|
+
def to_hash; end
|
|
3416
|
+
|
|
3417
|
+
# pkg:gem/csv#lib/csv/row.rb:697
|
|
3418
|
+
def to_s(**options); end
|
|
3419
|
+
|
|
3420
|
+
# pkg:gem/csv#lib/csv/row.rb:551
|
|
3421
|
+
def values_at(*headers_and_or_indices); end
|
|
3422
|
+
|
|
3423
|
+
protected
|
|
3424
|
+
|
|
3425
|
+
# Internal data format used to compare equality.
|
|
3426
|
+
#
|
|
3427
|
+
# pkg:gem/csv#lib/csv/row.rb:118
|
|
3428
|
+
def row; end
|
|
3429
|
+
|
|
3430
|
+
private
|
|
3431
|
+
|
|
3432
|
+
# :call-seq:
|
|
3433
|
+
# row.initialize_copy(other_row) -> self
|
|
3434
|
+
#
|
|
3435
|
+
# Calls superclass method.
|
|
3436
|
+
#
|
|
3437
|
+
# pkg:gem/csv#lib/csv/row.rb:130
|
|
3438
|
+
def initialize_copy(other); end
|
|
3439
|
+
end
|
|
3440
|
+
|
|
3441
|
+
# pkg:gem/csv#lib/csv.rb:2132
|
|
3442
|
+
class CSV::TSV < ::CSV
|
|
3443
|
+
# pkg:gem/csv#lib/csv.rb:2133
|
|
3444
|
+
def initialize(data, **options); end
|
|
3445
|
+
end
|
|
3446
|
+
|
|
3447
|
+
# = \CSV::Table
|
|
3448
|
+
# A \CSV::Table instance represents \CSV data.
|
|
3449
|
+
# (see {class CSV}[../CSV.html]).
|
|
3450
|
+
#
|
|
3451
|
+
# The instance may have:
|
|
3452
|
+
# - Rows: each is a Table::Row object.
|
|
3453
|
+
# - Headers: names for the columns.
|
|
3454
|
+
#
|
|
3455
|
+
# === Instance Methods
|
|
3456
|
+
#
|
|
3457
|
+
# \CSV::Table has three groups of instance methods:
|
|
3458
|
+
# - Its own internally defined instance methods.
|
|
3459
|
+
# - Methods included by module Enumerable.
|
|
3460
|
+
# - Methods delegated to class Array.:
|
|
3461
|
+
# * Array#empty?
|
|
3462
|
+
# * Array#length
|
|
3463
|
+
# * Array#size
|
|
3464
|
+
#
|
|
3465
|
+
# == Creating a \CSV::Table Instance
|
|
3466
|
+
#
|
|
3467
|
+
# Commonly, a new \CSV::Table instance is created by parsing \CSV source
|
|
3468
|
+
# using headers:
|
|
3469
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3470
|
+
# table = CSV.parse(source, headers: true)
|
|
3471
|
+
# table.class # => CSV::Table
|
|
3472
|
+
#
|
|
3473
|
+
# You can also create an instance directly. See ::new.
|
|
3474
|
+
#
|
|
3475
|
+
# == Headers
|
|
3476
|
+
#
|
|
3477
|
+
# If a table has headers, the headers serve as labels for the columns of data.
|
|
3478
|
+
# Each header serves as the label for its column.
|
|
3479
|
+
#
|
|
3480
|
+
# The headers for a \CSV::Table object are stored as an \Array of Strings.
|
|
3481
|
+
#
|
|
3482
|
+
# Commonly, headers are defined in the first row of \CSV source:
|
|
3483
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3484
|
+
# table = CSV.parse(source, headers: true)
|
|
3485
|
+
# table.headers # => ["Name", "Value"]
|
|
3486
|
+
#
|
|
3487
|
+
# If no headers are defined, the \Array is empty:
|
|
3488
|
+
# table = CSV::Table.new([])
|
|
3489
|
+
# table.headers # => []
|
|
3490
|
+
#
|
|
3491
|
+
# == Access Modes
|
|
3492
|
+
#
|
|
3493
|
+
# \CSV::Table provides three modes for accessing table data:
|
|
3494
|
+
# - \Row mode.
|
|
3495
|
+
# - Column mode.
|
|
3496
|
+
# - Mixed mode (the default for a new table).
|
|
3497
|
+
#
|
|
3498
|
+
# The access mode for a\CSV::Table instance affects the behavior
|
|
3499
|
+
# of some of its instance methods:
|
|
3500
|
+
# - #[]
|
|
3501
|
+
# - #[]=
|
|
3502
|
+
# - #delete
|
|
3503
|
+
# - #delete_if
|
|
3504
|
+
# - #each
|
|
3505
|
+
# - #values_at
|
|
3506
|
+
#
|
|
3507
|
+
# === \Row Mode
|
|
3508
|
+
#
|
|
3509
|
+
# Set a table to row mode with method #by_row!:
|
|
3510
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3511
|
+
# table = CSV.parse(source, headers: true)
|
|
3512
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
3513
|
+
#
|
|
3514
|
+
# Specify a single row by an \Integer index:
|
|
3515
|
+
# # Get a row.
|
|
3516
|
+
# table[1] # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
3517
|
+
# # Set a row, then get it.
|
|
3518
|
+
# table[1] = CSV::Row.new(['Name', 'Value'], ['bam', 3])
|
|
3519
|
+
# table[1] # => #<CSV::Row "Name":"bam" "Value":3>
|
|
3520
|
+
#
|
|
3521
|
+
# Specify a sequence of rows by a \Range:
|
|
3522
|
+
# # Get rows.
|
|
3523
|
+
# table[1..2] # => [#<CSV::Row "Name":"bam" "Value":3>, #<CSV::Row "Name":"baz" "Value":"2">]
|
|
3524
|
+
# # Set rows, then get them.
|
|
3525
|
+
# table[1..2] = [
|
|
3526
|
+
# CSV::Row.new(['Name', 'Value'], ['bat', 4]),
|
|
3527
|
+
# CSV::Row.new(['Name', 'Value'], ['bad', 5]),
|
|
3528
|
+
# ]
|
|
3529
|
+
# table[1..2] # => [["Name", #<CSV::Row "Name":"bat" "Value":4>], ["Value", #<CSV::Row "Name":"bad" "Value":5>]]
|
|
3530
|
+
#
|
|
3531
|
+
# === Column Mode
|
|
3532
|
+
#
|
|
3533
|
+
# Set a table to column mode with method #by_col!:
|
|
3534
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3535
|
+
# table = CSV.parse(source, headers: true)
|
|
3536
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
3537
|
+
#
|
|
3538
|
+
# Specify a column by an \Integer index:
|
|
3539
|
+
# # Get a column.
|
|
3540
|
+
# table[0]
|
|
3541
|
+
# # Set a column, then get it.
|
|
3542
|
+
# table[0] = ['FOO', 'BAR', 'BAZ']
|
|
3543
|
+
# table[0] # => ["FOO", "BAR", "BAZ"]
|
|
3544
|
+
#
|
|
3545
|
+
# Specify a column by its \String header:
|
|
3546
|
+
# # Get a column.
|
|
3547
|
+
# table['Name'] # => ["FOO", "BAR", "BAZ"]
|
|
3548
|
+
# # Set a column, then get it.
|
|
3549
|
+
# table['Name'] = ['Foo', 'Bar', 'Baz']
|
|
3550
|
+
# table['Name'] # => ["Foo", "Bar", "Baz"]
|
|
3551
|
+
#
|
|
3552
|
+
# === Mixed Mode
|
|
3553
|
+
#
|
|
3554
|
+
# In mixed mode, you can refer to either rows or columns:
|
|
3555
|
+
# - An \Integer index refers to a row.
|
|
3556
|
+
# - A \Range index refers to multiple rows.
|
|
3557
|
+
# - A \String index refers to a column.
|
|
3558
|
+
#
|
|
3559
|
+
# Set a table to mixed mode with method #by_col_or_row!:
|
|
3560
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3561
|
+
# table = CSV.parse(source, headers: true)
|
|
3562
|
+
# table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4>
|
|
3563
|
+
#
|
|
3564
|
+
# Specify a single row by an \Integer index:
|
|
3565
|
+
# # Get a row.
|
|
3566
|
+
# table[1] # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
3567
|
+
# # Set a row, then get it.
|
|
3568
|
+
# table[1] = CSV::Row.new(['Name', 'Value'], ['bam', 3])
|
|
3569
|
+
# table[1] # => #<CSV::Row "Name":"bam" "Value":3>
|
|
3570
|
+
#
|
|
3571
|
+
# Specify a sequence of rows by a \Range:
|
|
3572
|
+
# # Get rows.
|
|
3573
|
+
# table[1..2] # => [#<CSV::Row "Name":"bam" "Value":3>, #<CSV::Row "Name":"baz" "Value":"2">]
|
|
3574
|
+
# # Set rows, then get them.
|
|
3575
|
+
# table[1] = CSV::Row.new(['Name', 'Value'], ['bat', 4])
|
|
3576
|
+
# table[2] = CSV::Row.new(['Name', 'Value'], ['bad', 5])
|
|
3577
|
+
# table[1..2] # => [["Name", #<CSV::Row "Name":"bat" "Value":4>], ["Value", #<CSV::Row "Name":"bad" "Value":5>]]
|
|
3578
|
+
#
|
|
3579
|
+
# Specify a column by its \String header:
|
|
3580
|
+
# # Get a column.
|
|
3581
|
+
# table['Name'] # => ["foo", "bat", "bad"]
|
|
3582
|
+
# # Set a column, then get it.
|
|
3583
|
+
# table['Name'] = ['Foo', 'Bar', 'Baz']
|
|
3584
|
+
# table['Name'] # => ["Foo", "Bar", "Baz"]
|
|
3585
|
+
#
|
|
3586
|
+
# pkg:gem/csv#lib/csv/table.rb:144
|
|
3587
|
+
class CSV::Table
|
|
3588
|
+
include ::Enumerable
|
|
3589
|
+
extend ::Forwardable
|
|
3590
|
+
|
|
3591
|
+
# :call-seq:
|
|
3592
|
+
# CSV::Table.new(array_of_rows, headers = nil) -> csv_table
|
|
3593
|
+
#
|
|
3594
|
+
# Returns a new \CSV::Table object.
|
|
3595
|
+
#
|
|
3596
|
+
# - Argument +array_of_rows+ must be an \Array of CSV::Row objects.
|
|
3597
|
+
# - Argument +headers+, if given, may be an \Array of Strings.
|
|
3598
|
+
#
|
|
3599
|
+
# ---
|
|
3600
|
+
#
|
|
3601
|
+
# Create an empty \CSV::Table object:
|
|
3602
|
+
# table = CSV::Table.new([])
|
|
3603
|
+
# table # => #<CSV::Table mode:col_or_row row_count:1>
|
|
3604
|
+
#
|
|
3605
|
+
# Create a non-empty \CSV::Table object:
|
|
3606
|
+
# rows = [
|
|
3607
|
+
# CSV::Row.new([], []),
|
|
3608
|
+
# CSV::Row.new([], []),
|
|
3609
|
+
# CSV::Row.new([], []),
|
|
3610
|
+
# ]
|
|
3611
|
+
# table = CSV::Table.new(rows)
|
|
3612
|
+
# table # => #<CSV::Table mode:col_or_row row_count:4>
|
|
3613
|
+
#
|
|
3614
|
+
# ---
|
|
3615
|
+
#
|
|
3616
|
+
# If argument +headers+ is an \Array of Strings,
|
|
3617
|
+
# those Strings become the table's headers:
|
|
3618
|
+
# table = CSV::Table.new([], headers: ['Name', 'Age'])
|
|
3619
|
+
# table.headers # => ["Name", "Age"]
|
|
3620
|
+
#
|
|
3621
|
+
# If argument +headers+ is not given and the table has rows,
|
|
3622
|
+
# the headers are taken from the first row:
|
|
3623
|
+
# rows = [
|
|
3624
|
+
# CSV::Row.new(['Foo', 'Bar'], []),
|
|
3625
|
+
# CSV::Row.new(['foo', 'bar'], []),
|
|
3626
|
+
# CSV::Row.new(['FOO', 'BAR'], []),
|
|
3627
|
+
# ]
|
|
3628
|
+
# table = CSV::Table.new(rows)
|
|
3629
|
+
# table.headers # => ["Foo", "Bar"]
|
|
3630
|
+
#
|
|
3631
|
+
# If argument +headers+ is not given and the table is empty (has no rows),
|
|
3632
|
+
# the headers are also empty:
|
|
3633
|
+
# table = CSV::Table.new([])
|
|
3634
|
+
# table.headers # => []
|
|
3635
|
+
#
|
|
3636
|
+
# ---
|
|
3637
|
+
#
|
|
3638
|
+
# Raises an exception if argument +array_of_rows+ is not an \Array object:
|
|
3639
|
+
# # Raises NoMethodError (undefined method `first' for :foo:Symbol):
|
|
3640
|
+
# CSV::Table.new(:foo)
|
|
3641
|
+
#
|
|
3642
|
+
# Raises an exception if an element of +array_of_rows+ is not a \CSV::Table object:
|
|
3643
|
+
# # Raises NoMethodError (undefined method `headers' for :foo:Symbol):
|
|
3644
|
+
# CSV::Table.new([:foo])
|
|
3645
|
+
#
|
|
3646
|
+
# pkg:gem/csv#lib/csv/table.rb:199
|
|
3647
|
+
def initialize(array_of_rows, headers: T.unsafe(nil)); end
|
|
3648
|
+
|
|
3649
|
+
# :call-seq:
|
|
3650
|
+
# table << row_or_array -> self
|
|
3651
|
+
#
|
|
3652
|
+
# If +row_or_array+ is a \CSV::Row object,
|
|
3653
|
+
# it is appended to the table:
|
|
3654
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3655
|
+
# table = CSV.parse(source, headers: true)
|
|
3656
|
+
# table << CSV::Row.new(table.headers, ['bat', 3])
|
|
3657
|
+
# table[3] # => #<CSV::Row "Name":"bat" "Value":3>
|
|
3658
|
+
#
|
|
3659
|
+
# If +row_or_array+ is an \Array, it is used to create a new
|
|
3660
|
+
# \CSV::Row object which is then appended to the table:
|
|
3661
|
+
# table << ['bam', 4]
|
|
3662
|
+
# table[4] # => #<CSV::Row "Name":"bam" "Value":4>
|
|
3663
|
+
#
|
|
3664
|
+
# pkg:gem/csv#lib/csv/table.rb:762
|
|
3665
|
+
def <<(row_or_array); end
|
|
3666
|
+
|
|
3667
|
+
# :call-seq:
|
|
3668
|
+
# table == other_table -> true or false
|
|
3669
|
+
#
|
|
3670
|
+
# Returns +true+ if all each row of +self+ <tt>==</tt>
|
|
3671
|
+
# the corresponding row of +other_table+, otherwise, +false+.
|
|
3672
|
+
#
|
|
3673
|
+
# The access mode does no affect the result.
|
|
3674
|
+
#
|
|
3675
|
+
# Equal tables:
|
|
3676
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3677
|
+
# table = CSV.parse(source, headers: true)
|
|
3678
|
+
# other_table = CSV.parse(source, headers: true)
|
|
3679
|
+
# table == other_table # => true
|
|
3680
|
+
#
|
|
3681
|
+
# Different row count:
|
|
3682
|
+
# other_table.delete(2)
|
|
3683
|
+
# table == other_table # => false
|
|
3684
|
+
#
|
|
3685
|
+
# Different last row:
|
|
3686
|
+
# other_table << ['bat', 3]
|
|
3687
|
+
# table == other_table # => false
|
|
3688
|
+
#
|
|
3689
|
+
# pkg:gem/csv#lib/csv/table.rb:965
|
|
3690
|
+
def ==(other); end
|
|
3691
|
+
|
|
3692
|
+
# :call-seq:
|
|
3693
|
+
# table[n] -> row or column_data
|
|
3694
|
+
# table[range] -> array_of_rows or array_of_column_data
|
|
3695
|
+
# table[header] -> array_of_column_data
|
|
3696
|
+
#
|
|
3697
|
+
# Returns data from the table; does not modify the table.
|
|
3698
|
+
#
|
|
3699
|
+
# ---
|
|
3700
|
+
#
|
|
3701
|
+
# Fetch a \Row by Its \Integer Index::
|
|
3702
|
+
# - Form: <tt>table[n]</tt>, +n+ an integer.
|
|
3703
|
+
# - Access mode: <tt>:row</tt> or <tt>:col_or_row</tt>.
|
|
3704
|
+
# - Return value: _nth_ row of the table, if that row exists;
|
|
3705
|
+
# otherwise +nil+.
|
|
3706
|
+
#
|
|
3707
|
+
# Returns the _nth_ row of the table if that row exists:
|
|
3708
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3709
|
+
# table = CSV.parse(source, headers: true)
|
|
3710
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
3711
|
+
# table[1] # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
3712
|
+
# table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4>
|
|
3713
|
+
# table[1] # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
3714
|
+
#
|
|
3715
|
+
# Counts backward from the last row if +n+ is negative:
|
|
3716
|
+
# table[-1] # => #<CSV::Row "Name":"baz" "Value":"2">
|
|
3717
|
+
#
|
|
3718
|
+
# Returns +nil+ if +n+ is too large or too small:
|
|
3719
|
+
# table[4] # => nil
|
|
3720
|
+
# table[-4] # => nil
|
|
3721
|
+
#
|
|
3722
|
+
# Raises an exception if the access mode is <tt>:row</tt>
|
|
3723
|
+
# and +n+ is not an \Integer:
|
|
3724
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
3725
|
+
# # Raises TypeError (no implicit conversion of String into Integer):
|
|
3726
|
+
# table['Name']
|
|
3727
|
+
#
|
|
3728
|
+
# ---
|
|
3729
|
+
#
|
|
3730
|
+
# Fetch a Column by Its \Integer Index::
|
|
3731
|
+
# - Form: <tt>table[n]</tt>, +n+ an \Integer.
|
|
3732
|
+
# - Access mode: <tt>:col</tt>.
|
|
3733
|
+
# - Return value: _nth_ column of the table, if that column exists;
|
|
3734
|
+
# otherwise an \Array of +nil+ fields of length <tt>self.size</tt>.
|
|
3735
|
+
#
|
|
3736
|
+
# Returns the _nth_ column of the table if that column exists:
|
|
3737
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3738
|
+
# table = CSV.parse(source, headers: true)
|
|
3739
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
3740
|
+
# table[1] # => ["0", "1", "2"]
|
|
3741
|
+
#
|
|
3742
|
+
# Counts backward from the last column if +n+ is negative:
|
|
3743
|
+
# table[-2] # => ["foo", "bar", "baz"]
|
|
3744
|
+
#
|
|
3745
|
+
# Returns an \Array of +nil+ fields if +n+ is too large or too small:
|
|
3746
|
+
# table[4] # => [nil, nil, nil]
|
|
3747
|
+
# table[-4] # => [nil, nil, nil]
|
|
3748
|
+
#
|
|
3749
|
+
# ---
|
|
3750
|
+
#
|
|
3751
|
+
# Fetch Rows by \Range::
|
|
3752
|
+
# - Form: <tt>table[range]</tt>, +range+ a \Range object.
|
|
3753
|
+
# - Access mode: <tt>:row</tt> or <tt>:col_or_row</tt>.
|
|
3754
|
+
# - Return value: rows from the table, beginning at row <tt>range.start</tt>,
|
|
3755
|
+
# if those rows exists.
|
|
3756
|
+
#
|
|
3757
|
+
# Returns rows from the table, beginning at row <tt>range.first</tt>,
|
|
3758
|
+
# if those rows exist:
|
|
3759
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3760
|
+
# table = CSV.parse(source, headers: true)
|
|
3761
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
3762
|
+
# rows = table[1..2] # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
3763
|
+
# rows # => [#<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
|
|
3764
|
+
# table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4>
|
|
3765
|
+
# rows = table[1..2] # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
3766
|
+
# rows # => [#<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
|
|
3767
|
+
#
|
|
3768
|
+
# If there are too few rows, returns all from <tt>range.start</tt> to the end:
|
|
3769
|
+
# rows = table[1..50] # => #<CSV::Row "Name":"bar" "Value":"1">
|
|
3770
|
+
# rows # => [#<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
|
|
3771
|
+
#
|
|
3772
|
+
# Special case: if <tt>range.start == table.size</tt>, returns an empty \Array:
|
|
3773
|
+
# table[table.size..50] # => []
|
|
3774
|
+
#
|
|
3775
|
+
# If <tt>range.end</tt> is negative, calculates the ending index from the end:
|
|
3776
|
+
# rows = table[0..-1]
|
|
3777
|
+
# rows # => [#<CSV::Row "Name":"foo" "Value":"0">, #<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
|
|
3778
|
+
#
|
|
3779
|
+
# If <tt>range.start</tt> is negative, calculates the starting index from the end:
|
|
3780
|
+
# rows = table[-1..2]
|
|
3781
|
+
# rows # => [#<CSV::Row "Name":"baz" "Value":"2">]
|
|
3782
|
+
#
|
|
3783
|
+
# If <tt>range.start</tt> is larger than <tt>table.size</tt>, returns +nil+:
|
|
3784
|
+
# table[4..4] # => nil
|
|
3785
|
+
#
|
|
3786
|
+
# ---
|
|
3787
|
+
#
|
|
3788
|
+
# Fetch Columns by \Range::
|
|
3789
|
+
# - Form: <tt>table[range]</tt>, +range+ a \Range object.
|
|
3790
|
+
# - Access mode: <tt>:col</tt>.
|
|
3791
|
+
# - Return value: column data from the table, beginning at column <tt>range.start</tt>,
|
|
3792
|
+
# if those columns exist.
|
|
3793
|
+
#
|
|
3794
|
+
# Returns column values from the table, if the column exists;
|
|
3795
|
+
# the values are arranged by row:
|
|
3796
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3797
|
+
# table = CSV.parse(source, headers: true)
|
|
3798
|
+
# table.by_col!
|
|
3799
|
+
# table[0..1] # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
3800
|
+
#
|
|
3801
|
+
# Special case: if <tt>range.start == headers.size</tt>,
|
|
3802
|
+
# returns an \Array (size: <tt>table.size</tt>) of empty \Arrays:
|
|
3803
|
+
# table[table.headers.size..50] # => [[], [], []]
|
|
3804
|
+
#
|
|
3805
|
+
# If <tt>range.end</tt> is negative, calculates the ending index from the end:
|
|
3806
|
+
# table[0..-1] # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
3807
|
+
#
|
|
3808
|
+
# If <tt>range.start</tt> is negative, calculates the starting index from the end:
|
|
3809
|
+
# table[-2..2] # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
3810
|
+
#
|
|
3811
|
+
# If <tt>range.start</tt> is larger than <tt>table.size</tt>,
|
|
3812
|
+
# returns an \Array of +nil+ values:
|
|
3813
|
+
# table[4..4] # => [nil, nil, nil]
|
|
3814
|
+
#
|
|
3815
|
+
# ---
|
|
3816
|
+
#
|
|
3817
|
+
# Fetch a Column by Its \String Header::
|
|
3818
|
+
# - Form: <tt>table[header]</tt>, +header+ a \String header.
|
|
3819
|
+
# - Access mode: <tt>:col</tt> or <tt>:col_or_row</tt>
|
|
3820
|
+
# - Return value: column data from the table, if that +header+ exists.
|
|
3821
|
+
#
|
|
3822
|
+
# Returns column values from the table, if the column exists:
|
|
3823
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3824
|
+
# table = CSV.parse(source, headers: true)
|
|
3825
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
3826
|
+
# table['Name'] # => ["foo", "bar", "baz"]
|
|
3827
|
+
# table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4>
|
|
3828
|
+
# col = table['Name']
|
|
3829
|
+
# col # => ["foo", "bar", "baz"]
|
|
3830
|
+
#
|
|
3831
|
+
# Modifying the returned column values does not modify the table:
|
|
3832
|
+
# col[0] = 'bat'
|
|
3833
|
+
# col # => ["bat", "bar", "baz"]
|
|
3834
|
+
# table['Name'] # => ["foo", "bar", "baz"]
|
|
3835
|
+
#
|
|
3836
|
+
# Returns an \Array of +nil+ values if there is no such column:
|
|
3837
|
+
# table['Nosuch'] # => [nil, nil, nil]
|
|
3838
|
+
#
|
|
3839
|
+
# pkg:gem/csv#lib/csv/table.rb:514
|
|
3840
|
+
def [](index_or_header); end
|
|
3841
|
+
|
|
3842
|
+
# :call-seq:
|
|
3843
|
+
# table[n] = row -> row
|
|
3844
|
+
# table[n] = field_or_array_of_fields -> field_or_array_of_fields
|
|
3845
|
+
# table[header] = field_or_array_of_fields -> field_or_array_of_fields
|
|
3846
|
+
#
|
|
3847
|
+
# Puts data onto the table.
|
|
3848
|
+
#
|
|
3849
|
+
# ---
|
|
3850
|
+
#
|
|
3851
|
+
# Set a \Row by Its \Integer Index::
|
|
3852
|
+
# - Form: <tt>table[n] = row</tt>, +n+ an \Integer,
|
|
3853
|
+
# +row+ a \CSV::Row instance or an \Array of fields.
|
|
3854
|
+
# - Access mode: <tt>:row</tt> or <tt>:col_or_row</tt>.
|
|
3855
|
+
# - Return value: +row+.
|
|
3856
|
+
#
|
|
3857
|
+
# If the row exists, it is replaced:
|
|
3858
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3859
|
+
# table = CSV.parse(source, headers: true)
|
|
3860
|
+
# new_row = CSV::Row.new(['Name', 'Value'], ['bat', 3])
|
|
3861
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
3862
|
+
# return_value = table[0] = new_row
|
|
3863
|
+
# return_value.equal?(new_row) # => true # Returned the row
|
|
3864
|
+
# table[0].to_h # => {"Name"=>"bat", "Value"=>3}
|
|
3865
|
+
#
|
|
3866
|
+
# With access mode <tt>:col_or_row</tt>:
|
|
3867
|
+
# table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4>
|
|
3868
|
+
# table[0] = CSV::Row.new(['Name', 'Value'], ['bam', 4])
|
|
3869
|
+
# table[0].to_h # => {"Name"=>"bam", "Value"=>4}
|
|
3870
|
+
#
|
|
3871
|
+
# With an \Array instead of a \CSV::Row, inherits headers from the table:
|
|
3872
|
+
# array = ['bad', 5]
|
|
3873
|
+
# return_value = table[0] = array
|
|
3874
|
+
# return_value.equal?(array) # => true # Returned the array
|
|
3875
|
+
# table[0].to_h # => {"Name"=>"bad", "Value"=>5}
|
|
3876
|
+
#
|
|
3877
|
+
# If the row does not exist, extends the table by adding rows:
|
|
3878
|
+
# assigns rows with +nil+ as needed:
|
|
3879
|
+
# table.size # => 3
|
|
3880
|
+
# table[5] = ['bag', 6]
|
|
3881
|
+
# table.size # => 6
|
|
3882
|
+
# table[3] # => nil
|
|
3883
|
+
# table[4]# => nil
|
|
3884
|
+
# table[5].to_h # => {"Name"=>"bag", "Value"=>6}
|
|
3885
|
+
#
|
|
3886
|
+
# Note that the +nil+ rows are actually +nil+, not a row of +nil+ fields.
|
|
3887
|
+
#
|
|
3888
|
+
# ---
|
|
3889
|
+
#
|
|
3890
|
+
# Set a Column by Its \Integer Index::
|
|
3891
|
+
# - Form: <tt>table[n] = array_of_fields</tt>, +n+ an \Integer,
|
|
3892
|
+
# +array_of_fields+ an \Array of \String fields.
|
|
3893
|
+
# - Access mode: <tt>:col</tt>.
|
|
3894
|
+
# - Return value: +array_of_fields+.
|
|
3895
|
+
#
|
|
3896
|
+
# If the column exists, it is replaced:
|
|
3897
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3898
|
+
# table = CSV.parse(source, headers: true)
|
|
3899
|
+
# new_col = [3, 4, 5]
|
|
3900
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
3901
|
+
# return_value = table[1] = new_col
|
|
3902
|
+
# return_value.equal?(new_col) # => true # Returned the column
|
|
3903
|
+
# table[1] # => [3, 4, 5]
|
|
3904
|
+
# # The rows, as revised:
|
|
3905
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
3906
|
+
# table[0].to_h # => {"Name"=>"foo", "Value"=>3}
|
|
3907
|
+
# table[1].to_h # => {"Name"=>"bar", "Value"=>4}
|
|
3908
|
+
# table[2].to_h # => {"Name"=>"baz", "Value"=>5}
|
|
3909
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
3910
|
+
#
|
|
3911
|
+
# If there are too few values, fills with +nil+ values:
|
|
3912
|
+
# table[1] = [0]
|
|
3913
|
+
# table[1] # => [0, nil, nil]
|
|
3914
|
+
#
|
|
3915
|
+
# If there are too many values, ignores the extra values:
|
|
3916
|
+
# table[1] = [0, 1, 2, 3, 4]
|
|
3917
|
+
# table[1] # => [0, 1, 2]
|
|
3918
|
+
#
|
|
3919
|
+
# If a single value is given, replaces all fields in the column with that value:
|
|
3920
|
+
# table[1] = 'bat'
|
|
3921
|
+
# table[1] # => ["bat", "bat", "bat"]
|
|
3922
|
+
#
|
|
3923
|
+
# ---
|
|
3924
|
+
#
|
|
3925
|
+
# Set a Column by Its \String Header::
|
|
3926
|
+
# - Form: <tt>table[header] = field_or_array_of_fields</tt>,
|
|
3927
|
+
# +header+ a \String header, +field_or_array_of_fields+ a field value
|
|
3928
|
+
# or an \Array of \String fields.
|
|
3929
|
+
# - Access mode: <tt>:col</tt> or <tt>:col_or_row</tt>.
|
|
3930
|
+
# - Return value: +field_or_array_of_fields+.
|
|
3931
|
+
#
|
|
3932
|
+
# If the column exists, it is replaced:
|
|
3933
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3934
|
+
# table = CSV.parse(source, headers: true)
|
|
3935
|
+
# new_col = [3, 4, 5]
|
|
3936
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
3937
|
+
# return_value = table['Value'] = new_col
|
|
3938
|
+
# return_value.equal?(new_col) # => true # Returned the column
|
|
3939
|
+
# table['Value'] # => [3, 4, 5]
|
|
3940
|
+
# # The rows, as revised:
|
|
3941
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
3942
|
+
# table[0].to_h # => {"Name"=>"foo", "Value"=>3}
|
|
3943
|
+
# table[1].to_h # => {"Name"=>"bar", "Value"=>4}
|
|
3944
|
+
# table[2].to_h # => {"Name"=>"baz", "Value"=>5}
|
|
3945
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
3946
|
+
#
|
|
3947
|
+
# If there are too few values, fills with +nil+ values:
|
|
3948
|
+
# table['Value'] = [0]
|
|
3949
|
+
# table['Value'] # => [0, nil, nil]
|
|
3950
|
+
#
|
|
3951
|
+
# If there are too many values, ignores the extra values:
|
|
3952
|
+
# table['Value'] = [0, 1, 2, 3, 4]
|
|
3953
|
+
# table['Value'] # => [0, 1, 2]
|
|
3954
|
+
#
|
|
3955
|
+
# If the column does not exist, extends the table by adding columns:
|
|
3956
|
+
# table['Note'] = ['x', 'y', 'z']
|
|
3957
|
+
# table['Note'] # => ["x", "y", "z"]
|
|
3958
|
+
# # The rows, as revised:
|
|
3959
|
+
# table.by_row!
|
|
3960
|
+
# table[0].to_h # => {"Name"=>"foo", "Value"=>0, "Note"=>"x"}
|
|
3961
|
+
# table[1].to_h # => {"Name"=>"bar", "Value"=>1, "Note"=>"y"}
|
|
3962
|
+
# table[2].to_h # => {"Name"=>"baz", "Value"=>2, "Note"=>"z"}
|
|
3963
|
+
# table.by_col!
|
|
3964
|
+
#
|
|
3965
|
+
# If a single value is given, replaces all fields in the column with that value:
|
|
3966
|
+
# table['Value'] = 'bat'
|
|
3967
|
+
# table['Value'] # => ["bat", "bat", "bat"]
|
|
3968
|
+
#
|
|
3969
|
+
# pkg:gem/csv#lib/csv/table.rb:649
|
|
3970
|
+
def []=(index_or_header, value); end
|
|
3971
|
+
|
|
3972
|
+
# :call-seq:
|
|
3973
|
+
# table.by_col -> table_dup
|
|
3974
|
+
#
|
|
3975
|
+
# Returns a duplicate of +self+, in column mode
|
|
3976
|
+
# (see {Column Mode}[#class-CSV::Table-label-Column+Mode]):
|
|
3977
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3978
|
+
# table = CSV.parse(source, headers: true)
|
|
3979
|
+
# table.mode # => :col_or_row
|
|
3980
|
+
# dup_table = table.by_col
|
|
3981
|
+
# dup_table.mode # => :col
|
|
3982
|
+
# dup_table.equal?(table) # => false # It's a dup
|
|
3983
|
+
#
|
|
3984
|
+
# This may be used to chain method calls without changing the mode
|
|
3985
|
+
# (but also will affect performance and memory usage):
|
|
3986
|
+
# dup_table.by_col['Name']
|
|
3987
|
+
#
|
|
3988
|
+
# Also note that changes to the duplicate table will not affect the original.
|
|
3989
|
+
#
|
|
3990
|
+
# pkg:gem/csv#lib/csv/table.rb:242
|
|
3991
|
+
def by_col; end
|
|
3992
|
+
|
|
3993
|
+
# :call-seq:
|
|
3994
|
+
# table.by_col! -> self
|
|
3995
|
+
#
|
|
3996
|
+
# Sets the mode for +self+ to column mode
|
|
3997
|
+
# (see {Column Mode}[#class-CSV::Table-label-Column+Mode]); returns +self+:
|
|
3998
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
3999
|
+
# table = CSV.parse(source, headers: true)
|
|
4000
|
+
# table.mode # => :col_or_row
|
|
4001
|
+
# table1 = table.by_col!
|
|
4002
|
+
# table.mode # => :col
|
|
4003
|
+
# table1.equal?(table) # => true # Returned self
|
|
4004
|
+
#
|
|
4005
|
+
# pkg:gem/csv#lib/csv/table.rb:257
|
|
4006
|
+
def by_col!; end
|
|
4007
|
+
|
|
4008
|
+
# :call-seq:
|
|
4009
|
+
# table.by_col_or_row -> table_dup
|
|
4010
|
+
#
|
|
4011
|
+
# Returns a duplicate of +self+, in mixed mode
|
|
4012
|
+
# (see {Mixed Mode}[#class-CSV::Table-label-Mixed+Mode]):
|
|
4013
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4014
|
+
# table = CSV.parse(source, headers: true).by_col!
|
|
4015
|
+
# table.mode # => :col
|
|
4016
|
+
# dup_table = table.by_col_or_row
|
|
4017
|
+
# dup_table.mode # => :col_or_row
|
|
4018
|
+
# dup_table.equal?(table) # => false # It's a dup
|
|
4019
|
+
#
|
|
4020
|
+
# This may be used to chain method calls without changing the mode
|
|
4021
|
+
# (but also will affect performance and memory usage):
|
|
4022
|
+
# dup_table.by_col_or_row['Name']
|
|
4023
|
+
#
|
|
4024
|
+
# Also note that changes to the duplicate table will not affect the original.
|
|
4025
|
+
#
|
|
4026
|
+
# pkg:gem/csv#lib/csv/table.rb:280
|
|
4027
|
+
def by_col_or_row; end
|
|
4028
|
+
|
|
4029
|
+
# :call-seq:
|
|
4030
|
+
# table.by_col_or_row! -> self
|
|
4031
|
+
#
|
|
4032
|
+
# Sets the mode for +self+ to mixed mode
|
|
4033
|
+
# (see {Mixed Mode}[#class-CSV::Table-label-Mixed+Mode]); returns +self+:
|
|
4034
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4035
|
+
# table = CSV.parse(source, headers: true).by_col!
|
|
4036
|
+
# table.mode # => :col
|
|
4037
|
+
# table1 = table.by_col_or_row!
|
|
4038
|
+
# table.mode # => :col_or_row
|
|
4039
|
+
# table1.equal?(table) # => true # Returned self
|
|
4040
|
+
#
|
|
4041
|
+
# pkg:gem/csv#lib/csv/table.rb:295
|
|
4042
|
+
def by_col_or_row!; end
|
|
4043
|
+
|
|
4044
|
+
# :call-seq:
|
|
4045
|
+
# table.by_row -> table_dup
|
|
4046
|
+
#
|
|
4047
|
+
# Returns a duplicate of +self+, in row mode
|
|
4048
|
+
# (see {Row Mode}[#class-CSV::Table-label-Row+Mode]):
|
|
4049
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4050
|
+
# table = CSV.parse(source, headers: true)
|
|
4051
|
+
# table.mode # => :col_or_row
|
|
4052
|
+
# dup_table = table.by_row
|
|
4053
|
+
# dup_table.mode # => :row
|
|
4054
|
+
# dup_table.equal?(table) # => false # It's a dup
|
|
4055
|
+
#
|
|
4056
|
+
# This may be used to chain method calls without changing the mode
|
|
4057
|
+
# (but also will affect performance and memory usage):
|
|
4058
|
+
# dup_table.by_row[1]
|
|
4059
|
+
#
|
|
4060
|
+
# Also note that changes to the duplicate table will not affect the original.
|
|
4061
|
+
#
|
|
4062
|
+
# pkg:gem/csv#lib/csv/table.rb:318
|
|
4063
|
+
def by_row; end
|
|
4064
|
+
|
|
4065
|
+
# :call-seq:
|
|
4066
|
+
# table.by_row! -> self
|
|
4067
|
+
#
|
|
4068
|
+
# Sets the mode for +self+ to row mode
|
|
4069
|
+
# (see {Row Mode}[#class-CSV::Table-label-Row+Mode]); returns +self+:
|
|
4070
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4071
|
+
# table = CSV.parse(source, headers: true)
|
|
4072
|
+
# table.mode # => :col_or_row
|
|
4073
|
+
# table1 = table.by_row!
|
|
4074
|
+
# table.mode # => :row
|
|
4075
|
+
# table1.equal?(table) # => true # Returned self
|
|
4076
|
+
#
|
|
4077
|
+
# pkg:gem/csv#lib/csv/table.rb:333
|
|
4078
|
+
def by_row!; end
|
|
4079
|
+
|
|
4080
|
+
# :call-seq:
|
|
4081
|
+
# table.delete(*indexes) -> deleted_values
|
|
4082
|
+
# table.delete(*headers) -> deleted_values
|
|
4083
|
+
#
|
|
4084
|
+
# If the access mode is <tt>:row</tt> or <tt>:col_or_row</tt>,
|
|
4085
|
+
# and each argument is either an \Integer or a \Range,
|
|
4086
|
+
# returns deleted rows.
|
|
4087
|
+
# Otherwise, returns deleted columns data.
|
|
4088
|
+
#
|
|
4089
|
+
# In either case, the returned values are in the order
|
|
4090
|
+
# specified by the arguments. Arguments may be repeated.
|
|
4091
|
+
#
|
|
4092
|
+
# ---
|
|
4093
|
+
#
|
|
4094
|
+
# Returns rows as an \Array of \CSV::Row objects.
|
|
4095
|
+
#
|
|
4096
|
+
# One index:
|
|
4097
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4098
|
+
# table = CSV.parse(source, headers: true)
|
|
4099
|
+
# deleted_values = table.delete(0)
|
|
4100
|
+
# deleted_values # => [#<CSV::Row "Name":"foo" "Value":"0">]
|
|
4101
|
+
#
|
|
4102
|
+
# Two indexes:
|
|
4103
|
+
# table = CSV.parse(source, headers: true)
|
|
4104
|
+
# deleted_values = table.delete(2, 0)
|
|
4105
|
+
# deleted_values # => [#<CSV::Row "Name":"baz" "Value":"2">, #<CSV::Row "Name":"foo" "Value":"0">]
|
|
4106
|
+
#
|
|
4107
|
+
# ---
|
|
4108
|
+
#
|
|
4109
|
+
# Returns columns data as column Arrays.
|
|
4110
|
+
#
|
|
4111
|
+
# One header:
|
|
4112
|
+
# table = CSV.parse(source, headers: true)
|
|
4113
|
+
# deleted_values = table.delete('Name')
|
|
4114
|
+
# deleted_values # => ["foo", "bar", "baz"]
|
|
4115
|
+
#
|
|
4116
|
+
# Two headers:
|
|
4117
|
+
# table = CSV.parse(source, headers: true)
|
|
4118
|
+
# deleted_values = table.delete('Value', 'Name')
|
|
4119
|
+
# deleted_values # => [["0", "1", "2"], ["foo", "bar", "baz"]]
|
|
4120
|
+
#
|
|
4121
|
+
# pkg:gem/csv#lib/csv/table.rb:834
|
|
4122
|
+
def delete(*indexes_or_headers); end
|
|
4123
|
+
|
|
4124
|
+
# :call-seq:
|
|
4125
|
+
# table.delete_if {|row_or_column| ... } -> self
|
|
4126
|
+
#
|
|
4127
|
+
# Removes rows or columns for which the block returns a truthy value;
|
|
4128
|
+
# returns +self+.
|
|
4129
|
+
#
|
|
4130
|
+
# Removes rows when the access mode is <tt>:row</tt> or <tt>:col_or_row</tt>;
|
|
4131
|
+
# calls the block with each \CSV::Row object:
|
|
4132
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4133
|
+
# table = CSV.parse(source, headers: true)
|
|
4134
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
4135
|
+
# table.size # => 3
|
|
4136
|
+
# table.delete_if {|row| row['Name'].start_with?('b') }
|
|
4137
|
+
# table.size # => 1
|
|
4138
|
+
#
|
|
4139
|
+
# Removes columns when the access mode is <tt>:col</tt>;
|
|
4140
|
+
# calls the block with each column as a 2-element array
|
|
4141
|
+
# containing the header and an \Array of column fields:
|
|
4142
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4143
|
+
# table = CSV.parse(source, headers: true)
|
|
4144
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
4145
|
+
# table.headers.size # => 2
|
|
4146
|
+
# table.delete_if {|column_data| column_data[1].include?('2') }
|
|
4147
|
+
# table.headers.size # => 1
|
|
4148
|
+
#
|
|
4149
|
+
# Returns a new \Enumerator if no block is given:
|
|
4150
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4151
|
+
# table = CSV.parse(source, headers: true)
|
|
4152
|
+
# table.delete_if # => #<Enumerator: #<CSV::Table mode:col_or_row row_count:4>:delete_if>
|
|
4153
|
+
#
|
|
4154
|
+
# pkg:gem/csv#lib/csv/table.rb:887
|
|
4155
|
+
def delete_if(&block); end
|
|
4156
|
+
|
|
4157
|
+
# Extracts the nested value specified by the sequence of +index+ or +header+ objects by calling dig at each step,
|
|
4158
|
+
# returning nil if any intermediate step is nil.
|
|
4159
|
+
#
|
|
4160
|
+
# pkg:gem/csv#lib/csv/table.rb:1021
|
|
4161
|
+
def dig(index_or_header, *index_or_headers); end
|
|
4162
|
+
|
|
4163
|
+
# :call-seq:
|
|
4164
|
+
# table.each {|row_or_column| ... ) -> self
|
|
4165
|
+
#
|
|
4166
|
+
# Calls the block with each row or column; returns +self+.
|
|
4167
|
+
#
|
|
4168
|
+
# When the access mode is <tt>:row</tt> or <tt>:col_or_row</tt>,
|
|
4169
|
+
# calls the block with each \CSV::Row object:
|
|
4170
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4171
|
+
# table = CSV.parse(source, headers: true)
|
|
4172
|
+
# table.by_row! # => #<CSV::Table mode:row row_count:4>
|
|
4173
|
+
# table.each {|row| p row }
|
|
4174
|
+
# Output:
|
|
4175
|
+
# #<CSV::Row "Name":"foo" "Value":"0">
|
|
4176
|
+
# #<CSV::Row "Name":"bar" "Value":"1">
|
|
4177
|
+
# #<CSV::Row "Name":"baz" "Value":"2">
|
|
4178
|
+
#
|
|
4179
|
+
# When the access mode is <tt>:col</tt>,
|
|
4180
|
+
# calls the block with each column as a 2-element array
|
|
4181
|
+
# containing the header and an \Array of column fields:
|
|
4182
|
+
# table.by_col! # => #<CSV::Table mode:col row_count:4>
|
|
4183
|
+
# table.each {|column_data| p column_data }
|
|
4184
|
+
# Output:
|
|
4185
|
+
# ["Name", ["foo", "bar", "baz"]]
|
|
4186
|
+
# ["Value", ["0", "1", "2"]]
|
|
4187
|
+
#
|
|
4188
|
+
# Returns a new \Enumerator if no block is given:
|
|
4189
|
+
# table.each # => #<Enumerator: #<CSV::Table mode:col row_count:4>:each>
|
|
4190
|
+
#
|
|
4191
|
+
# pkg:gem/csv#lib/csv/table.rb:930
|
|
4192
|
+
def each(&block); end
|
|
4193
|
+
|
|
4194
|
+
# pkg:gem/csv#lib/csv/table.rb:223
|
|
4195
|
+
def empty?(*args, **_arg1, &block); end
|
|
4196
|
+
|
|
4197
|
+
# :call-seq:
|
|
4198
|
+
# table.headers -> array_of_headers
|
|
4199
|
+
#
|
|
4200
|
+
# Returns a new \Array containing the \String headers for the table.
|
|
4201
|
+
#
|
|
4202
|
+
# If the table is not empty, returns the headers from the first row:
|
|
4203
|
+
# rows = [
|
|
4204
|
+
# CSV::Row.new(['Foo', 'Bar'], []),
|
|
4205
|
+
# CSV::Row.new(['FOO', 'BAR'], []),
|
|
4206
|
+
# CSV::Row.new(['foo', 'bar'], []),
|
|
4207
|
+
# ]
|
|
4208
|
+
# table = CSV::Table.new(rows)
|
|
4209
|
+
# table.headers # => ["Foo", "Bar"]
|
|
4210
|
+
# table.delete(0)
|
|
4211
|
+
# table.headers # => ["FOO", "BAR"]
|
|
4212
|
+
# table.delete(0)
|
|
4213
|
+
# table.headers # => ["foo", "bar"]
|
|
4214
|
+
#
|
|
4215
|
+
# If the table is empty, returns a copy of the headers in the table itself:
|
|
4216
|
+
# table.delete(0)
|
|
4217
|
+
# table.headers # => ["Foo", "Bar"]
|
|
4218
|
+
#
|
|
4219
|
+
# pkg:gem/csv#lib/csv/table.rb:360
|
|
4220
|
+
def headers; end
|
|
4221
|
+
|
|
4222
|
+
# :call-seq:
|
|
4223
|
+
# table.inspect => string
|
|
4224
|
+
#
|
|
4225
|
+
# Returns a <tt>US-ASCII</tt>-encoded \String showing table:
|
|
4226
|
+
# - Class: <tt>CSV::Table</tt>.
|
|
4227
|
+
# - Access mode: <tt>:row</tt>, <tt>:col</tt>, or <tt>:col_or_row</tt>.
|
|
4228
|
+
# - Size: Row count, including the header row.
|
|
4229
|
+
#
|
|
4230
|
+
# Example:
|
|
4231
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4232
|
+
# table = CSV.parse(source, headers: true)
|
|
4233
|
+
# table.inspect # => "#<CSV::Table mode:col_or_row row_count:4>\nName,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4234
|
+
#
|
|
4235
|
+
# pkg:gem/csv#lib/csv/table.rb:1048
|
|
4236
|
+
def inspect; end
|
|
4237
|
+
|
|
4238
|
+
# pkg:gem/csv#lib/csv/table.rb:223
|
|
4239
|
+
def length(*args, **_arg1, &block); end
|
|
4240
|
+
|
|
4241
|
+
# The current access mode for indexing and iteration.
|
|
4242
|
+
#
|
|
4243
|
+
# pkg:gem/csv#lib/csv/table.rb:214
|
|
4244
|
+
def mode; end
|
|
4245
|
+
|
|
4246
|
+
# :call-seq:
|
|
4247
|
+
# table.push(*rows_or_arrays) -> self
|
|
4248
|
+
#
|
|
4249
|
+
# A shortcut for appending multiple rows. Equivalent to:
|
|
4250
|
+
# rows.each {|row| self << row }
|
|
4251
|
+
#
|
|
4252
|
+
# Each argument may be either a \CSV::Row object or an \Array:
|
|
4253
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4254
|
+
# table = CSV.parse(source, headers: true)
|
|
4255
|
+
# rows = [
|
|
4256
|
+
# CSV::Row.new(table.headers, ['bat', 3]),
|
|
4257
|
+
# ['bam', 4]
|
|
4258
|
+
# ]
|
|
4259
|
+
# table.push(*rows)
|
|
4260
|
+
# table[3..4] # => [#<CSV::Row "Name":"bat" "Value":3>, #<CSV::Row "Name":"bam" "Value":4>]
|
|
4261
|
+
#
|
|
4262
|
+
# pkg:gem/csv#lib/csv/table.rb:788
|
|
4263
|
+
def push(*rows); end
|
|
4264
|
+
|
|
4265
|
+
# pkg:gem/csv#lib/csv/table.rb:223
|
|
4266
|
+
def size(*args, **_arg1, &block); end
|
|
4267
|
+
|
|
4268
|
+
# :call-seq:
|
|
4269
|
+
# table.to_a -> array_of_arrays
|
|
4270
|
+
#
|
|
4271
|
+
# Returns the table as an \Array of \Arrays;
|
|
4272
|
+
# the headers are in the first row:
|
|
4273
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4274
|
+
# table = CSV.parse(source, headers: true)
|
|
4275
|
+
# table.to_a # => [["Name", "Value"], ["foo", "0"], ["bar", "1"], ["baz", "2"]]
|
|
4276
|
+
#
|
|
4277
|
+
# pkg:gem/csv#lib/csv/table.rb:978
|
|
4278
|
+
def to_a; end
|
|
4279
|
+
|
|
4280
|
+
# :call-seq:
|
|
4281
|
+
# table.to_csv(**options) -> csv_string
|
|
4282
|
+
#
|
|
4283
|
+
# Returns the table as \CSV string.
|
|
4284
|
+
# See {Options for Generating}[../CSV.html#class-CSV-label-Options+for+Generating].
|
|
4285
|
+
#
|
|
4286
|
+
# Defaults option +write_headers+ to +true+:
|
|
4287
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4288
|
+
# table = CSV.parse(source, headers: true)
|
|
4289
|
+
# table.to_csv # => "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4290
|
+
#
|
|
4291
|
+
# Omits the headers if option +write_headers+ is given as +false+
|
|
4292
|
+
# (see {Option +write_headers+}[../CSV.html#class-CSV-label-Option+write_headers]):
|
|
4293
|
+
# table.to_csv(write_headers: false) # => "foo,0\nbar,1\nbaz,2\n"
|
|
4294
|
+
#
|
|
4295
|
+
# Limit rows if option +limit+ is given like +2+:
|
|
4296
|
+
# table.to_csv(limit: 2) # => "Name,Value\nfoo,0\nbar,1\n"
|
|
4297
|
+
#
|
|
4298
|
+
# pkg:gem/csv#lib/csv/table.rb:1004
|
|
4299
|
+
def to_csv(write_headers: T.unsafe(nil), limit: T.unsafe(nil), **options); end
|
|
4300
|
+
|
|
4301
|
+
# pkg:gem/csv#lib/csv/table.rb:1015
|
|
4302
|
+
def to_s(write_headers: T.unsafe(nil), limit: T.unsafe(nil), **options); end
|
|
4303
|
+
|
|
4304
|
+
# :call-seq:
|
|
4305
|
+
# table.values_at(*indexes) -> array_of_rows
|
|
4306
|
+
# table.values_at(*headers) -> array_of_columns_data
|
|
4307
|
+
#
|
|
4308
|
+
# If the access mode is <tt>:row</tt> or <tt>:col_or_row</tt>,
|
|
4309
|
+
# and each argument is either an \Integer or a \Range,
|
|
4310
|
+
# returns rows.
|
|
4311
|
+
# Otherwise, returns columns data.
|
|
4312
|
+
#
|
|
4313
|
+
# In either case, the returned values are in the order
|
|
4314
|
+
# specified by the arguments. Arguments may be repeated.
|
|
4315
|
+
#
|
|
4316
|
+
# ---
|
|
4317
|
+
#
|
|
4318
|
+
# Returns rows as an \Array of \CSV::Row objects.
|
|
4319
|
+
#
|
|
4320
|
+
# No argument:
|
|
4321
|
+
# source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
|
|
4322
|
+
# table = CSV.parse(source, headers: true)
|
|
4323
|
+
# table.values_at # => []
|
|
4324
|
+
#
|
|
4325
|
+
# One index:
|
|
4326
|
+
# values = table.values_at(0)
|
|
4327
|
+
# values # => [#<CSV::Row "Name":"foo" "Value":"0">]
|
|
4328
|
+
#
|
|
4329
|
+
# Two indexes:
|
|
4330
|
+
# values = table.values_at(2, 0)
|
|
4331
|
+
# values # => [#<CSV::Row "Name":"baz" "Value":"2">, #<CSV::Row "Name":"foo" "Value":"0">]
|
|
4332
|
+
#
|
|
4333
|
+
# One \Range:
|
|
4334
|
+
# values = table.values_at(1..2)
|
|
4335
|
+
# values # => [#<CSV::Row "Name":"bar" "Value":"1">, #<CSV::Row "Name":"baz" "Value":"2">]
|
|
4336
|
+
#
|
|
4337
|
+
# \Ranges and indexes:
|
|
4338
|
+
# values = table.values_at(0..1, 1..2, 0, 2)
|
|
4339
|
+
# pp values
|
|
4340
|
+
# Output:
|
|
4341
|
+
# [#<CSV::Row "Name":"foo" "Value":"0">,
|
|
4342
|
+
# #<CSV::Row "Name":"bar" "Value":"1">,
|
|
4343
|
+
# #<CSV::Row "Name":"bar" "Value":"1">,
|
|
4344
|
+
# #<CSV::Row "Name":"baz" "Value":"2">,
|
|
4345
|
+
# #<CSV::Row "Name":"foo" "Value":"0">,
|
|
4346
|
+
# #<CSV::Row "Name":"baz" "Value":"2">]
|
|
4347
|
+
#
|
|
4348
|
+
# ---
|
|
4349
|
+
#
|
|
4350
|
+
# Returns columns data as row Arrays,
|
|
4351
|
+
# each consisting of the specified columns data for that row:
|
|
4352
|
+
# values = table.values_at('Name')
|
|
4353
|
+
# values # => [["foo"], ["bar"], ["baz"]]
|
|
4354
|
+
# values = table.values_at('Value', 'Name')
|
|
4355
|
+
# values # => [["0", "foo"], ["1", "bar"], ["2", "baz"]]
|
|
4356
|
+
#
|
|
4357
|
+
# pkg:gem/csv#lib/csv/table.rb:734
|
|
4358
|
+
def values_at(*indices_or_headers); end
|
|
4359
|
+
|
|
4360
|
+
protected
|
|
4361
|
+
|
|
4362
|
+
# Internal data format used to compare equality.
|
|
4363
|
+
#
|
|
4364
|
+
# pkg:gem/csv#lib/csv/table.rb:217
|
|
4365
|
+
def table; end
|
|
4366
|
+
end
|
|
4367
|
+
|
|
4368
|
+
# Note: Don't use this class directly. This is an internal class.
|
|
4369
|
+
#
|
|
4370
|
+
# pkg:gem/csv#lib/csv/writer.rb:8
|
|
4371
|
+
class CSV::Writer
|
|
4372
|
+
# pkg:gem/csv#lib/csv/writer.rb:16
|
|
4373
|
+
def initialize(output, options); end
|
|
4374
|
+
|
|
4375
|
+
# Adds a new row
|
|
4376
|
+
#
|
|
4377
|
+
# pkg:gem/csv#lib/csv/writer.rb:31
|
|
4378
|
+
def <<(row); end
|
|
4379
|
+
|
|
4380
|
+
# pkg:gem/csv#lib/csv/writer.rb:14
|
|
4381
|
+
def headers; end
|
|
4382
|
+
|
|
4383
|
+
# A CSV::Writer receives an output, prepares the header, format and output.
|
|
4384
|
+
# It allows us to write new rows in the object and rewind it.
|
|
4385
|
+
#
|
|
4386
|
+
# pkg:gem/csv#lib/csv/writer.rb:13
|
|
4387
|
+
def lineno; end
|
|
4388
|
+
|
|
4389
|
+
# Winds back to the beginning
|
|
4390
|
+
#
|
|
4391
|
+
# pkg:gem/csv#lib/csv/writer.rb:63
|
|
4392
|
+
def rewind; end
|
|
4393
|
+
|
|
4394
|
+
private
|
|
4395
|
+
|
|
4396
|
+
# pkg:gem/csv#lib/csv/writer.rb:69
|
|
4397
|
+
def prepare; end
|
|
4398
|
+
|
|
4399
|
+
# pkg:gem/csv#lib/csv/writer.rb:105
|
|
4400
|
+
def prepare_force_quotes_fields(force_quotes); end
|
|
4401
|
+
|
|
4402
|
+
# pkg:gem/csv#lib/csv/writer.rb:132
|
|
4403
|
+
def prepare_format; end
|
|
4404
|
+
|
|
4405
|
+
# pkg:gem/csv#lib/csv/writer.rb:77
|
|
4406
|
+
def prepare_header; end
|
|
4407
|
+
|
|
4408
|
+
# pkg:gem/csv#lib/csv/writer.rb:162
|
|
4409
|
+
def prepare_output; end
|
|
4410
|
+
|
|
4411
|
+
# pkg:gem/csv#lib/csv/writer.rb:189
|
|
4412
|
+
def quote(field, i); end
|
|
4413
|
+
|
|
4414
|
+
# pkg:gem/csv#lib/csv/writer.rb:180
|
|
4415
|
+
def quote_field(field); end
|
|
4416
|
+
end
|
|
4417
|
+
|
|
4418
|
+
class Object < ::BasicObject
|
|
4419
|
+
include ::Kernel
|
|
4420
|
+
include ::PP::ObjectMixin
|
|
4421
|
+
|
|
4422
|
+
private
|
|
4423
|
+
|
|
4424
|
+
# Passes +args+ to CSV::instance.
|
|
4425
|
+
#
|
|
4426
|
+
# CSV("CSV,data").read
|
|
4427
|
+
# #=> [["CSV", "data"]]
|
|
4428
|
+
#
|
|
4429
|
+
# If a block is given, the instance is passed the block and the return value
|
|
4430
|
+
# becomes the return value of the block.
|
|
4431
|
+
#
|
|
4432
|
+
# CSV("CSV,data") { |c|
|
|
4433
|
+
# c.read.any? { |a| a.include?("data") }
|
|
4434
|
+
# } #=> true
|
|
4435
|
+
#
|
|
4436
|
+
# CSV("CSV,data") { |c|
|
|
4437
|
+
# c.read.any? { |a| a.include?("zombies") }
|
|
4438
|
+
# } #=> false
|
|
4439
|
+
#
|
|
4440
|
+
# CSV options may also be given.
|
|
4441
|
+
#
|
|
4442
|
+
# io = StringIO.new
|
|
4443
|
+
# CSV(io, col_sep: ";") { |csv| csv << ["a", "b", "c"] }
|
|
4444
|
+
#
|
|
4445
|
+
# This API is not Ractor-safe.
|
|
4446
|
+
#
|
|
4447
|
+
# pkg:gem/csv#lib/csv.rb:3011
|
|
4448
|
+
def CSV(*args, **options, &block); end
|
|
4449
|
+
end
|
|
4450
|
+
|
|
4451
|
+
# pkg:gem/csv#lib/csv/core_ext/string.rb:1
|
|
4452
|
+
class String
|
|
4453
|
+
include ::Comparable
|
|
4454
|
+
|
|
4455
|
+
# Equivalent to CSV::parse_line(self, options)
|
|
4456
|
+
#
|
|
4457
|
+
# "CSV,data".parse_csv
|
|
4458
|
+
# #=> ["CSV", "data"]
|
|
4459
|
+
#
|
|
4460
|
+
# pkg:gem/csv#lib/csv/core_ext/string.rb:6
|
|
4461
|
+
def parse_csv(**options); end
|
|
4462
|
+
end
|