class Para::Exporter::Xls

Protected Instance Methods

binary?() click to toggle source
# File lib/para/exporter/xls.rb, line 21
def binary?
  true
end
encode(string) click to toggle source
# File lib/para/exporter/xls.rb, line 54
def encode(string)
  string.presence && string.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
end
extension() click to toggle source
# File lib/para/exporter/xls.rb, line 9
def extension
  '.xls'
end
fields() click to toggle source
# File lib/para/exporter/xls.rb, line 50
def fields
  fail NotImplementedError
end
generate() click to toggle source
# File lib/para/exporter/xls.rb, line 25
def generate
  generate_workbook do |workbook|
    sheet = workbook.create_worksheet

    # Add headers
    sheet.row(0).concat headers

    # Add content rows
    resources.each_with_index do |resource , index|
      sheet.row(index + 1).concat row_for(resource)
    end
  end
end
generate_workbook(&block) click to toggle source
# File lib/para/exporter/xls.rb, line 39
def generate_workbook(&block)
  workbook = Spreadsheet::Workbook.new

  block.call(workbook)

  buffer = StringIO.new
  workbook.write(buffer)
  buffer.rewind
  buffer.read
end
mime_type() click to toggle source
# File lib/para/exporter/xls.rb, line 17
def mime_type
  'application/vnd.ms-excel'
end
name() click to toggle source
# File lib/para/exporter/xls.rb, line 13
def name
  'export'
end