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, UnexpectedError, UnoptimizedStringIO
Instance Method Summary
collapse
Constructor Details
#initialize(input, options) ⇒ Parser
Returns a new instance of Parser.
335
336
337
338
339
340
341
|
# File 'lib/csv/parser.rb', line 335
def initialize(input, options)
@input = input
@options = options
@samples = []
prepare
end
|
Instance Method Details
#column_separator ⇒ Object
343
344
345
|
# File 'lib/csv/parser.rb', line 343
def column_separator
@column_separator
end
|
#field_size_limit ⇒ Object
355
356
357
|
# File 'lib/csv/parser.rb', line 355
def field_size_limit
@max_field_size&.succ
end
|
375
376
377
|
# File 'lib/csv/parser.rb', line 375
def
@use_headers and @headers.nil?
end
|
371
372
373
|
# File 'lib/csv/parser.rb', line 371
def
@headers
end
|
#liberal_parsing? ⇒ Boolean
387
388
389
|
# File 'lib/csv/parser.rb', line 387
def liberal_parsing?
@liberal_parsing
end
|
#line ⇒ Object
395
396
397
|
# File 'lib/csv/parser.rb', line 395
def line
last_line
end
|
#lineno ⇒ Object
391
392
393
|
# File 'lib/csv/parser.rb', line 391
def lineno
@lineno
end
|
#max_field_size ⇒ Object
359
360
361
|
# File 'lib/csv/parser.rb', line 359
def max_field_size
@max_field_size
end
|
#parse(&block) ⇒ Object
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
# File 'lib/csv/parser.rb', line 399
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
raise InvalidEncodingError.new(@encoding, lineno)
rescue UnexpectedError => error
if @scanner
ignore_broken_line
lineno = @lineno
else
lineno = @lineno + 1
end
message = "This should not be happen: #{error.message}: "
message += "Please report this to https://github.com/ruby/csv/issues"
raise MalformedCSVError.new(message, lineno)
end
end
|
#quote_character ⇒ Object
351
352
353
|
# File 'lib/csv/parser.rb', line 351
def quote_character
@quote_character
end
|
379
380
381
|
# File 'lib/csv/parser.rb', line 379
def
@return_headers
end
|
#row_separator ⇒ Object
347
348
349
|
# File 'lib/csv/parser.rb', line 347
def row_separator
@row_separator
end
|
#skip_blanks? ⇒ Boolean
383
384
385
|
# File 'lib/csv/parser.rb', line 383
def skip_blanks?
@skip_blanks
end
|
#skip_lines ⇒ Object
363
364
365
|
# File 'lib/csv/parser.rb', line 363
def skip_lines
@skip_lines
end
|
#unconverted_fields? ⇒ Boolean
367
368
369
|
# File 'lib/csv/parser.rb', line 367
def unconverted_fields?
@unconverted_fields
end
|
440
441
442
|
# File 'lib/csv/parser.rb', line 440
def
@use_headers
end
|