Class: Exportable::ExportMethods::CsvExporter::Exporter
- Inherits:
-
Object
- Object
- Exportable::ExportMethods::CsvExporter::Exporter
- Defined in:
- lib/exportable/export_methods/csv_exporter.rb
Overview
Exporter class for CSV Exporter
Instance Method Summary collapse
- #export(options) ⇒ Object
-
#initialize(model) ⇒ Exporter
constructor
A new instance of Exporter.
Constructor Details
#initialize(model) ⇒ Exporter
Returns a new instance of Exporter.
18 19 20 |
# File 'lib/exportable/export_methods/csv_exporter.rb', line 18 def initialize(model) @model = model end |
Instance Method Details
#export(options) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/exportable/export_methods/csv_exporter.rb', line 22 def export() CSV.generate do |csv| csv << [:fields].map(&:to_s) if [:header] @model.where(nil).find_each do |record| csv << [:fields].map { |attr| record.send(attr).to_s } end end end |