Class: TreasureData::FileReader::SeparatedValueParsingReader

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

Overview

TODO: encoding handling

Instance Method Summary collapse

Constructor Details

#initialize(io, error, opts) ⇒ SeparatedValueParsingReader

Returns a new instance of SeparatedValueParsingReader.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/td/file_reader.rb', line 84

def initialize(io, error, opts)
  if encoding = opts[:encoding]
    io.set_encoding(encoding, :invalid => :replace, :undef => :replace) if io.respond_to?(:set_encoding)
  end

  # csv module is pure Ruby implementation.
  # So this may cause slow performance in large dataset.
  csv_opts = {
    :col_sep => opts[:delimiter_expr],
    :row_sep => $/,
    :skip_blanks => true
  }
  csv_opts[:quote_char] = opts[:quote_char] if opts[:quote_char]
  begin
    require 'fastercsv'
    @io = FasterCSV.new(io, **csv_opts)
  rescue LoadError => e
    require 'csv'
    @io = CSV.new(io, **csv_opts)
  end
  @error = error
  # @escape_char = opts[:escape_char]
end

Instance Method Details

#forwardObject



108
109
110
# File 'lib/td/file_reader.rb', line 108

def forward
  @io.readline
end