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
Constant Summary
collapse
- ARGF_OBJECT_ID =
ARGF.object_id
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(input, options) ⇒ Parser
Returns a new instance of Parser.
348
349
350
351
352
353
354
|
# File 'lib/csv/parser.rb', line 348
def initialize(input, options)
@input = input
@options = options
@samples = []
prepare
end
|
Class Method Details
.eof?(input) ⇒ Boolean
Convenient method to check whether the give input reached EOF or not.
25
26
27
28
29
30
31
|
# File 'lib/csv/parser.rb', line 25
def eof?(input)
input.object_id != ARGF_OBJECT_ID and
input.respond_to?(:eof) and
input.eof?
end
|
Instance Method Details
#column_separator ⇒ Object
356
357
358
|
# File 'lib/csv/parser.rb', line 356
def column_separator
@column_separator
end
|
#field_size_limit ⇒ Object
368
369
370
|
# File 'lib/csv/parser.rb', line 368
def field_size_limit
@max_field_size&.succ
end
|
388
389
390
|
# File 'lib/csv/parser.rb', line 388
def
@use_headers and @headers.nil?
end
|
384
385
386
|
# File 'lib/csv/parser.rb', line 384
def
@headers
end
|
#liberal_parsing? ⇒ Boolean
400
401
402
|
# File 'lib/csv/parser.rb', line 400
def liberal_parsing?
@liberal_parsing
end
|
#line ⇒ Object
408
409
410
|
# File 'lib/csv/parser.rb', line 408
def line
last_line
end
|
#lineno ⇒ Object
404
405
406
|
# File 'lib/csv/parser.rb', line 404
def lineno
@lineno
end
|
#max_field_size ⇒ Object
372
373
374
|
# File 'lib/csv/parser.rb', line 372
def max_field_size
@max_field_size
end
|
#parse(&block) ⇒ Object
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
439
440
441
442
443
444
445
|
# File 'lib/csv/parser.rb', line 412
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
__send__(@parse_method, &block)
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
364
365
366
|
# File 'lib/csv/parser.rb', line 364
def quote_character
@quote_character
end
|
392
393
394
|
# File 'lib/csv/parser.rb', line 392
def
@return_headers
end
|
#row_separator ⇒ Object
360
361
362
|
# File 'lib/csv/parser.rb', line 360
def row_separator
@row_separator
end
|
#skip_blanks? ⇒ Boolean
396
397
398
|
# File 'lib/csv/parser.rb', line 396
def skip_blanks?
@skip_blanks
end
|
#skip_lines ⇒ Object
376
377
378
|
# File 'lib/csv/parser.rb', line 376
def skip_lines
@skip_lines
end
|
#unconverted_fields? ⇒ Boolean
380
381
382
|
# File 'lib/csv/parser.rb', line 380
def unconverted_fields?
@unconverted_fields
end
|
447
448
449
|
# File 'lib/csv/parser.rb', line 447
def
@use_headers
end
|