Class: Traject::CSVWriter
- Inherits:
-
DelimitedWriter
- Object
- DelimitedWriter
- Traject::CSVWriter
- 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
- #_write(data) ⇒ Object
-
#escape(x) ⇒ Object
Let CSV take care of the comma escaping.
-
#initialize(*args) ⇒ CSVWriter
constructor
A new instance of CSVWriter.
-
#open_output_file ⇒ Object
Turn the output file into a CSV writer.
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_file ⇒ Object
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 |