Class: ActiveList::Exporters::OpenDocumentSpreadsheetExporter

Inherits:
AbstractExporter
  • Object
show all
Defined in:
lib/active_list/exporters/open_document_spreadsheet_exporter.rb

Instance Attribute Summary

Attributes inherited from AbstractExporter

#generator, #table

Instance Method Summary collapse

Methods inherited from AbstractExporter

#columns_headers, #columns_to_array, #columns_to_hash, #file_name_code, #generate_file_code, #initialize

Constructor Details

This class inherits a constructor from ActiveList::Exporters::AbstractExporter

Instance Method Details

#file_extensionObject



12
13
14
# File 'lib/active_list/exporters/open_document_spreadsheet_exporter.rb', line 12

def file_extension
  'ods'
end

#generate_data_codeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/active_list/exporters/open_document_spreadsheet_exporter.rb', line 20

def generate_data_code
  record = 'r'

  code = generator.select_data_code(paginate: false)
  code << "    records = \#{generator.records_variable_name}\n    data = RODF::Spreadsheet.new\n\n    data.instance_eval do\n      office_style :head, family: :cell do\n        property :text, 'font-weight': :bold\n        property :paragraph, 'text-align': :center\n      end\n\n      table \#{table.model.name}.model_name.human do\n        row do\n          \#{columns_to_array(:header)}.each do |header|\n            cell header, style: :head\n          end\n        end\n\n        for \#{record} in records\n          row do\n            \#{columns_to_array(:body, record: record)}.each do |value|\n              cell value\n            end\n          end\n        end\n      end\n    end\n  RUBY\n  code.c\nend\n"

#mime_typeObject



16
17
18
# File 'lib/active_list/exporters/open_document_spreadsheet_exporter.rb', line 16

def mime_type
  Mime[:ods]
end

#send_data_codeObject



54
55
56
# File 'lib/active_list/exporters/open_document_spreadsheet_exporter.rb', line 54

def send_data_code
  "send_data(data.bytes, type: #{mime_type.to_s.inspect}, disposition: 'inline', filename: file_name.parameterize + '.#{file_extension}')\n".c
end