Class: ArcFurnace::CSVSink
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(filename:, fields:, encoding: 'UTF-8', force_quotes: false) ⇒ CSVSink
constructor
A new instance of CSVSink.
- #row(hash) ⇒ Object
Methods inherited from Sink
Constructor Details
#initialize(filename:, fields:, encoding: 'UTF-8', force_quotes: false) ⇒ CSVSink
Returns a new instance of CSVSink.
7 8 9 10 11 |
# File 'lib/arc-furnace/csv_sink.rb', line 7 def initialize(filename: , fields: , encoding: 'UTF-8', force_quotes: false) @csv = CSV.open(filename, 'wb', encoding: encoding, headers: true, force_quotes: force_quotes) @fields = fields csv << fields end |
Instance Method Details
#finalize ⇒ Object
13 14 15 |
# File 'lib/arc-furnace/csv_sink.rb', line 13 def finalize csv.close end |
#row(hash) ⇒ Object
17 18 19 |
# File 'lib/arc-furnace/csv_sink.rb', line 17 def row(hash) csv << fields.map { |field_id| hash[field_id] } end |