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.
329
330
331
332
333
334
335
|
# File 'lib/csv/parser.rb', line 329
def initialize(input, options)
@input = input
@options = options
@samples = []
prepare
end
|
Instance Method Details
#column_separator ⇒ Object
337
338
339
|
# File 'lib/csv/parser.rb', line 337
def column_separator
@column_separator
end
|
#field_size_limit ⇒ Object
349
350
351
|
# File 'lib/csv/parser.rb', line 349
def field_size_limit
@max_field_size&.succ
end
|
369
370
371
|
# File 'lib/csv/parser.rb', line 369
def
@use_headers and @headers.nil?
end
|
365
366
367
|
# File 'lib/csv/parser.rb', line 365
def
@headers
end
|
#liberal_parsing? ⇒ Boolean
381
382
383
|
# File 'lib/csv/parser.rb', line 381
def liberal_parsing?
@liberal_parsing
end
|
#line ⇒ Object
389
390
391
|
# File 'lib/csv/parser.rb', line 389
def line
last_line
end
|
#lineno ⇒ Object
385
386
387
|
# File 'lib/csv/parser.rb', line 385
def lineno
@lineno
end
|
#max_field_size ⇒ Object
353
354
355
|
# File 'lib/csv/parser.rb', line 353
def max_field_size
@max_field_size
end
|
#parse(&block) ⇒ Object
393
394
395
396
397
398
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
|
# File 'lib/csv/parser.rb', line 393
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)
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
345
346
347
|
# File 'lib/csv/parser.rb', line 345
def quote_character
@quote_character
end
|
373
374
375
|
# File 'lib/csv/parser.rb', line 373
def
@return_headers
end
|
#row_separator ⇒ Object
341
342
343
|
# File 'lib/csv/parser.rb', line 341
def row_separator
@row_separator
end
|
#skip_blanks? ⇒ Boolean
377
378
379
|
# File 'lib/csv/parser.rb', line 377
def skip_blanks?
@skip_blanks
end
|
#skip_lines ⇒ Object
357
358
359
|
# File 'lib/csv/parser.rb', line 357
def skip_lines
@skip_lines
end
|
#unconverted_fields? ⇒ Boolean
361
362
363
|
# File 'lib/csv/parser.rb', line 361
def unconverted_fields?
@unconverted_fields
end
|
435
436
437
|
# File 'lib/csv/parser.rb', line 435
def
@use_headers
end
|