Class: Philiprehberger::CsvKit::Writer::StreamWriter
- Inherits:
-
Object
- Object
- Philiprehberger::CsvKit::Writer::StreamWriter
- Defined in:
- lib/philiprehberger/csv_kit/writer.rb
Overview
Incremental writer that streams rows to an IO object one at a time.
Instance Method Summary collapse
-
#<<(row) ⇒ self
Append a single row to the CSV output.
-
#initialize(io, headers:, dialect: nil) ⇒ StreamWriter
constructor
A new instance of StreamWriter.
Constructor Details
#initialize(io, headers:, dialect: nil) ⇒ StreamWriter
Returns a new instance of StreamWriter.
63 64 65 66 67 68 69 |
# File 'lib/philiprehberger/csv_kit/writer.rb', line 63 def initialize(io, headers:, dialect: nil) @headers = headers.map(&:to_sym) csv_opts = {} csv_opts = Dialect.new(dialect).merge_into(csv_opts) if dialect @csv = CSV.new(io, **csv_opts) @csv << @headers end |
Instance Method Details
#<<(row) ⇒ self
Append a single row to the CSV output.
75 76 77 78 |
# File 'lib/philiprehberger/csv_kit/writer.rb', line 75 def <<(row) @csv << row_values(row) self end |