Class: Exportable::ExportMethods::CsvExporter::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/exportable/export_methods/csv_exporter.rb

Overview

Exporter class for CSV Exporter

Instance Method Summary collapse

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(options)
  CSV.generate do |csv|
    csv << options[:fields].map(&:to_s) if options[:header]
    @model.where(nil).find_each do |record|
      csv << options[:fields].map { |attr| record.send(attr).to_s }
    end
  end
end