Class: RedshiftConnector::Reader::RedshiftCSV

Inherits:
Abstract
  • Object
show all
Defined in:
lib/redshift_connector/reader/redshift_csv.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: ScanBuffer

Constant Summary

Constants inherited from Abstract

Abstract::READER_CLASSES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

declare_reader, get_reader_class

Constructor Details

#initialize(f) ⇒ RedshiftCSV

f

IO



16
17
18
19
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 16

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

Class Method Details

.data_object?(key) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 11

def self.data_object?(key)
  /\.csv(?:\.|\z)/ =~ File.basename(key)
end

Instance Method Details

#each_rowObject Also known as: each



21
22
23
24
25
26
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 21

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

#read_rowObject



30
31
32
33
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 30

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