class RedshiftCsvFile::ScanBuffer
Constants
- MAX_COLUMN_LENGTH
Public Class Methods
new(f)
click to toggle source
# File lib/redshift_csv_file.rb, line 59 def initialize(f) @f = f @s = StringScanner.new("") @eof = false end
Public Instance Methods
eof?()
click to toggle source
# File lib/redshift_csv_file.rb, line 65 def eof? @s.eos? && @eof end
fill_buffer()
click to toggle source
# File lib/redshift_csv_file.rb, line 92 def fill_buffer line = @f.gets if line @s << line true else @eof = true false end end
lineno()
click to toggle source
# File lib/redshift_csv_file.rb, line 69 def lineno @f.lineno end
next_row()
click to toggle source
# File lib/redshift_csv_file.rb, line 73 def next_row fill_buffer end
read_eol()
click to toggle source
# File lib/redshift_csv_file.rb, line 107 def read_eol @s.skip(/[ \t\r]*(?:\n|\z)/) end
read_separator()
click to toggle source
# File lib/redshift_csv_file.rb, line 103 def read_separator @s.skip(/[ \t]*,/) end
scan_column()
click to toggle source
# File lib/redshift_csv_file.rb, line 79 def scan_column s = @s s.skip(/[ \t]+/) until column = s.scan(/"(?:\\.|[^"\\])*"/m) fill_buffer or return nil return nil if s.eos? if s.rest_size > MAX_COLUMN_LENGTH raise MalformedCSVException, "CSV parse error: too long column at line #{@f.lineno}" end end column end