Class: ActiveList::Exporters::CsvExporter
Instance Attribute Summary
#generator, #table
Instance Method Summary
collapse
#columns_headers, #columns_to_array, #columns_to_hash, #file_name_code, #generate_file_code, #initialize
Instance Method Details
#file_extension ⇒ Object
5
6
7
|
# File 'lib/active_list/exporters/csv_exporter.rb', line 5
def file_extension
'csv'
end
|
#generate_data_code ⇒ Object
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_type ⇒ Object
9
10
11
|
# File 'lib/active_list/exporters/csv_exporter.rb', line 9
def mime_type
Mime[:csv]
end
|
#send_data_code ⇒ Object
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
|