Class: Traject::CSVWriter
- Inherits:
-
DelimitedWriter
- Object
- LineWriter
- 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 Attribute Summary
Attributes inherited from DelimitedWriter
#delimiter, #edelim, #eidelim, #header, #internal_delimiter
Attributes inherited from LineWriter
#output_file, #settings, #write_mutex
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.
Methods inherited from DelimitedWriter
#escaped_delimiter, #output_values, #raw_output_values, #serialize, #write_header
Methods inherited from LineWriter
#close, #put, #serialize, #should_close_stream?
Constructor Details
#initialize(*args) ⇒ CSVWriter
Returns a new instance of CSVWriter.
11 12 13 14 |
# File 'lib/traject/csv_writer.rb', line 11 def initialize(*args) super self.delimiter = nil # Let CSV take care of it end |
Instance Method Details
#_write(data) ⇒ Object
16 17 18 |
# File 'lib/traject/csv_writer.rb', line 16 def _write(data) @output_file << data end |
#escape(x) ⇒ Object
Let CSV take care of the comma escaping
27 28 29 30 31 |
# File 'lib/traject/csv_writer.rb', line 27 def escape(x) x = x.to_s x.gsub! internal_delimiter, @eidelim x end |
#open_output_file ⇒ Object
Turn the output file into a CSV writer
21 22 23 24 |
# File 'lib/traject/csv_writer.rb', line 21 def open_output_file of = super CSV.new(of) end |