Class: CSV::Parser
- Inherits:
-
Object
show all
- Defined in:
- lib/csv/parser.rb
Overview
Note: Don’t use this class directly. This is an internal class.
Defined Under Namespace
Classes: InputsScanner, InvalidEncoding, Scanner, UnoptimizedStringIO
Instance Method Summary
collapse
Constructor Details
#initialize(input, options) ⇒ Parser
Returns a new instance of Parser.
258
259
260
261
262
263
264
|
# File 'lib/csv/parser.rb', line 258
def initialize(input, options)
@input = input
@options = options
@samples = []
prepare
end
|
Instance Method Details
#column_separator ⇒ Object
266
267
268
|
# File 'lib/csv/parser.rb', line 266
def column_separator
@column_separator
end
|
#field_size_limit ⇒ Object
278
279
280
|
# File 'lib/csv/parser.rb', line 278
def field_size_limit
@field_size_limit
end
|
294
295
296
|
# File 'lib/csv/parser.rb', line 294
def
@use_headers and @headers.nil?
end
|
290
291
292
|
# File 'lib/csv/parser.rb', line 290
def
@headers
end
|
#liberal_parsing? ⇒ Boolean
306
307
308
|
# File 'lib/csv/parser.rb', line 306
def liberal_parsing?
@liberal_parsing
end
|
#line ⇒ Object
314
315
316
|
# File 'lib/csv/parser.rb', line 314
def line
last_line
end
|
#lineno ⇒ Object
310
311
312
|
# File 'lib/csv/parser.rb', line 310
def lineno
@lineno
end
|
#parse(&block) ⇒ Object
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
# File 'lib/csv/parser.rb', line 318
def parse(&block)
return to_enum(__method__) unless block_given?
if @return_headers and @headers and @raw_headers
= Row.new(@headers, @raw_headers, true)
if @unconverted_fields
= add_unconverted_fields(, [])
end
yield
end
begin
@scanner ||= build_scanner
if quote_character.nil?
parse_no_quote(&block)
elsif @need_robust_parsing
parse_quotable_robust(&block)
else
parse_quotable_loose(&block)
end
rescue InvalidEncoding
if @scanner
ignore_broken_line
lineno = @lineno
else
lineno = @lineno + 1
end
message = "Invalid byte sequence in #{@encoding}"
raise MalformedCSVError.new(message, lineno)
end
end
|
#quote_character ⇒ Object
274
275
276
|
# File 'lib/csv/parser.rb', line 274
def quote_character
@quote_character
end
|
298
299
300
|
# File 'lib/csv/parser.rb', line 298
def
@return_headers
end
|
#row_separator ⇒ Object
270
271
272
|
# File 'lib/csv/parser.rb', line 270
def row_separator
@row_separator
end
|
#skip_blanks? ⇒ Boolean
302
303
304
|
# File 'lib/csv/parser.rb', line 302
def skip_blanks?
@skip_blanks
end
|
#skip_lines ⇒ Object
282
283
284
|
# File 'lib/csv/parser.rb', line 282
def skip_lines
@skip_lines
end
|
#unconverted_fields? ⇒ Boolean
286
287
288
|
# File 'lib/csv/parser.rb', line 286
def unconverted_fields?
@unconverted_fields
end
|
350
351
352
|
# File 'lib/csv/parser.rb', line 350
def
@use_headers
end
|