Class: ActiveList::Exporters::CsvExporter

Inherits:
AbstractExporter show all
Defined in:
lib/active_list/exporters/csv_exporter.rb

Direct Known Subclasses

ExcelCsvExporter

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



5
6
7
# File 'lib/active_list/exporters/csv_exporter.rb', line 5

def file_extension
  'csv'
end

#generate_data_codeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_list/exporters/csv_exporter.rb', line 13

def generate_data_code
  record = 'r'
  code = generator.select_data_code(paginate: false)
  code << "data = ::CSV.generate do |csv|\n"
  code << "  csv << [#{columns_to_array(:header).join(', ')}]\n"
  code << "  for #{record} in #{generator.records_variable_name}\n"
  code << "    csv << [#{columns_to_array(:body, record: record).join(', ')}]\n"
  code << "  end\n"
  code << "end\n"
  code.c
end

#mime_typeObject



9
10
11
# File 'lib/active_list/exporters/csv_exporter.rb', line 9

def mime_type
  Mime[:csv]
end

#send_data_codeObject



25
26
27
# File 'lib/active_list/exporters/csv_exporter.rb', line 25

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