Class: RedshiftCsvFile

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift_csv_file.rb

Overview

Reads CSV file generated by Redshift UNLOAD statement (with option ADDQUOTES ESCAPE). UNLOAD escapes data by ‘' (backslash character), we cannot use standard CSV class.

Defined Under Namespace

Classes: MalformedCSVException, ScanBuffer

Instance Method Summary collapse

Constructor Details

#initialize(f) ⇒ RedshiftCsvFile

f

IO



9
10
11
12
# File 'lib/redshift_csv_file.rb', line 9

def initialize(f)
  @f = f
  @s = ScanBuffer.new(@f)
end

Instance Method Details

#each_rowObject Also known as: each



14
15
16
17
18
19
# File 'lib/redshift_csv_file.rb', line 14

def each_row
  s = @s
  while row = parse_row(@s)
    yield row
  end
end

#read_rowObject



23
24
25
26
# File 'lib/redshift_csv_file.rb', line 23

def read_row
  return nil if @s.eof?
  parse_row(@s)
end