Class: ArcFurnace::CSVSink

Inherits:
Sink
  • Object
show all
Defined in:
lib/arc-furnace/csv_sink.rb

Instance Method Summary collapse

Methods inherited from Sink

#prepare

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

#finalizeObject



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