Class: TreasureData::FileReader::SeparatedValueParsingReader
- Inherits:
-
Object
- Object
- TreasureData::FileReader::SeparatedValueParsingReader
- Defined in:
- lib/td/file_reader.rb
Overview
TODO: encoding handling
Instance Method Summary collapse
- #forward ⇒ Object
-
#initialize(io, error, opts) ⇒ SeparatedValueParsingReader
constructor
A new instance of SeparatedValueParsingReader.
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
#forward ⇒ Object
108 109 110 |
# File 'lib/td/file_reader.rb', line 108 def forward @io.readline end |