Class: RedshiftCsvFile::ScanBuffer
- Inherits:
-
Object
- Object
- RedshiftCsvFile::ScanBuffer
- Defined in:
- lib/redshift_csv_file.rb
Constant Summary collapse
- MAX_COLUMN_LENGTH =
1.2MB
(1.2 * (1024 ** 3)).to_i
Instance Method Summary collapse
- #eof? ⇒ Boolean
- #fill_buffer ⇒ Object
-
#initialize(f) ⇒ ScanBuffer
constructor
A new instance of ScanBuffer.
- #lineno ⇒ Object
- #next_row ⇒ Object
- #read_eol ⇒ Object
- #read_separator ⇒ Object
- #scan_column ⇒ Object
Constructor Details
#initialize(f) ⇒ ScanBuffer
Returns a new instance of ScanBuffer.
59 60 61 62 63 |
# File 'lib/redshift_csv_file.rb', line 59 def initialize(f) @f = f @s = StringScanner.new("") @eof = false end |
Instance Method Details
#eof? ⇒ Boolean
65 66 67 |
# File 'lib/redshift_csv_file.rb', line 65 def eof? @s.eos? && @eof end |
#fill_buffer ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# 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 ⇒ Object
69 70 71 |
# File 'lib/redshift_csv_file.rb', line 69 def lineno @f.lineno end |
#next_row ⇒ Object
73 74 75 |
# File 'lib/redshift_csv_file.rb', line 73 def next_row fill_buffer end |
#read_eol ⇒ Object
107 108 109 |
# File 'lib/redshift_csv_file.rb', line 107 def read_eol @s.skip(/[ \t\r]*(?:\n|\z)/) end |
#read_separator ⇒ Object
103 104 105 |
# File 'lib/redshift_csv_file.rb', line 103 def read_separator @s.skip(/[ \t]*,/) end |
#scan_column ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# 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 |