Class: ArcFurnace::ExcelSink

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

Instance Method Summary collapse

Methods inherited from Sink

#prepare

Constructor Details

#initialize(filename:, fields:, types: nil) ⇒ ExcelSink

Returns a new instance of ExcelSink.



8
9
10
11
12
13
14
15
16
# File 'lib/arc-furnace/excel_sink.rb', line 8

def initialize(filename: , fields:, types: nil)
  @filename = filename
  @fields = fields
  @package = Axlsx::Package.new
  @workbook = package.workbook
  @worksheet = workbook.add_worksheet(name: 'Sheet1')
  @types = types ? types : []
  worksheet.add_row(fields)
end

Instance Method Details

#finalizeObject



18
19
20
# File 'lib/arc-furnace/excel_sink.rb', line 18

def finalize
  package.serialize(filename)
end

#row(hash) ⇒ Object



22
23
24
# File 'lib/arc-furnace/excel_sink.rb', line 22

def row(hash)
  worksheet.add_row(fields.map { |field_id| hash[field_id] }, types: types)
end