Skip to Content Skip to Search

Note: Don’t use this class directly. This is an internal class.

Namespace
Methods
C
F
H
L
M
N
P
Q
R
S
U

Constants

SCANNER_TEST = (ENV["CSV_PARSER_SCANNER_TEST"] == "yes")
 
SCANNER_TEST_CHUNK_SIZE_NAME = "CSV_PARSER_SCANNER_TEST_CHUNK_SIZE"
 
SCANNER_TEST_CHUNK_SIZE_VALUE = ENV[SCANNER_TEST_CHUNK_SIZE_NAME]
 
STRING_SCANNER_SCAN_ACCEPT_STRING = false
 

Class Public methods

new(input, options)

# File ruby/lib/csv/parser.rb, line 326
def initialize(input, options)
  @input = input
  @options = options
  @samples = []

  prepare
end

Instance Public methods

column_separator()

# File ruby/lib/csv/parser.rb, line 334
def column_separator
  @column_separator
end

field_size_limit()

# File ruby/lib/csv/parser.rb, line 346
def field_size_limit
  @max_field_size&.succ
end

header_row?()

# File ruby/lib/csv/parser.rb, line 366
def header_row?
  @use_headers and @headers.nil?
end

headers()

# File ruby/lib/csv/parser.rb, line 362
def headers
  @headers
end

liberal_parsing?()

# File ruby/lib/csv/parser.rb, line 378
def liberal_parsing?
  @liberal_parsing
end

line()

# File ruby/lib/csv/parser.rb, line 386
def line
  last_line
end

lineno()

# File ruby/lib/csv/parser.rb, line 382
def lineno
  @lineno
end

max_field_size()

# File ruby/lib/csv/parser.rb, line 350
def max_field_size
  @max_field_size
end

parse(&block)

# File ruby/lib/csv/parser.rb, line 390
def parse(&block)
  return to_enum(__method__) unless block_given?

  if @return_headers and @headers and @raw_headers
    headers = Row.new(@headers, @raw_headers, true)
    if @unconverted_fields
      headers = add_unconverted_fields(headers, [])
    end
    yield headers
  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()

# File ruby/lib/csv/parser.rb, line 342
def quote_character
  @quote_character
end

return_headers?()

# File ruby/lib/csv/parser.rb, line 370
def return_headers?
  @return_headers
end

row_separator()

# File ruby/lib/csv/parser.rb, line 338
def row_separator
  @row_separator
end

skip_blanks?()

# File ruby/lib/csv/parser.rb, line 374
def skip_blanks?
  @skip_blanks
end

skip_lines()

# File ruby/lib/csv/parser.rb, line 354
def skip_lines
  @skip_lines
end

unconverted_fields?()

# File ruby/lib/csv/parser.rb, line 358
def unconverted_fields?
  @unconverted_fields
end

use_headers?()

# File ruby/lib/csv/parser.rb, line 431
def use_headers?
  @use_headers
end