class Burner::Library::Serialize::Csv

Take an array of arrays and create a CSV. You can optionally pre-pend a byte order mark, see Burner::Modeling::ByteOrderMark for acceptable options.

Expected Payload input: array of arrays. Payload output: a serialized CSV string.

Attributes

byte_order_mark[R]

Public Class Methods

new(byte_order_mark: nil, name: '', register: DEFAULT_REGISTER) click to toggle source
Calls superclass method Burner::JobWithRegister::new
# File lib/burner/library/serialize/csv.rb, line 21
def initialize(byte_order_mark: nil, name: '', register: DEFAULT_REGISTER)
  super(name: name, register: register)

  @byte_order_mark = Modeling::ByteOrderMark.resolve(byte_order_mark)

  freeze
end

Public Instance Methods

perform(_output, payload) click to toggle source
# File lib/burner/library/serialize/csv.rb, line 29
def perform(_output, payload)
  serialized_rows = CSV.generate(options) do |csv|
    array(payload[register]).each do |row|
      csv << row
    end
  end

  payload[register] = "#{byte_order_mark}#{serialized_rows}"
end

Private Instance Methods

options() click to toggle source
# File lib/burner/library/serialize/csv.rb, line 41
def options
  {
    headers: false,
    write_headers: false
  }
end