Class: ActiveExport::Csv
- Inherits:
-
Base
- Object
- Base
- ActiveExport::Csv
show all
- Defined in:
- lib/active_export/csv.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #eval_methods, #label_keys, #label_prefix, #namespace, #options, #source, #source_name
Instance Method Summary
collapse
Methods inherited from Base
build_label_keys_and_eval_methods, #build_label_keys_and_eval_methods!, #convert, #default_scope, export, #export_data, export_file, #find_in_batches_options, #generate_header, #generate_value, #initialize, #key_name, translate, #translate
Instance Method Details
#csv_options ⇒ Object
26
27
28
|
# File 'lib/active_export/csv.rb', line 26
def csv_options
self.config.default_csv_options.merge( self.options[:csv_options] || {} )
end
|
#export(data) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/active_export/csv.rb', line 7
def export(data)
CSV.generate(csv_options) do |csv|
csv << if
export_data(data, csv)
end
end
|
#export_file(data, filename) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/active_export/csv.rb', line 14
def export_file(data, filename)
File.atomic_write(filename.to_s) do |file|
CSV.open(file, "wb", csv_options) do |csv|
csv << if
export_data(data, csv)
end
end
filename
end
|
30
31
32
|
# File 'lib/active_export/csv.rb', line 30
def
{ header: true }.merge(self.options)[:header]
end
|