Class: Traject::CSVWriter

Inherits:
DelimitedWriter
  • Object
show all
Defined in:
lib/traject/csv_writer.rb

Overview

A CSV-writer, for folks who like that sort of thing. Use DelimitedWriter for non-CSV lines (e.g., tab-delimited)

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CSVWriter

Returns a new instance of CSVWriter.



10
11
12
13
# File 'lib/traject/csv_writer.rb', line 10

def initialize(*args)
  super
  self.delimiter = nil # Let CSV take care of it
end

Instance Method Details

#_write(data) ⇒ Object



15
16
17
# File 'lib/traject/csv_writer.rb', line 15

def _write(data)
  @output_file << data
end

#escape(x) ⇒ Object

Let CSV take care of the comma escaping



26
27
28
29
30
31
32
33
34
35
# File 'lib/traject/csv_writer.rb', line 26

def escape(x)
  x = x.to_s

  if x.frozen?
    x = x.dup
  end

  x.gsub! internal_delimiter, @eidelim
  x
end

#open_output_fileObject

Turn the output file into a CSV writer



20
21
22
23
# File 'lib/traject/csv_writer.rb', line 20

def open_output_file
  of = super
  CSV.new(of)
end