Class: Exportable::ExportMethods::XlsExporter::Exporter
- Inherits:
-
Object
- Object
- Exportable::ExportMethods::XlsExporter::Exporter
- Defined in:
- lib/exportable/export_methods/xls_exporter.rb
Overview
Exporter class for XLS Exporter
Instance Method Summary collapse
- #export(options) ⇒ Object
-
#initialize(model) ⇒ Exporter
constructor
A new instance of Exporter.
- #write_io_output ⇒ Object
Constructor Details
#initialize(model) ⇒ Exporter
Returns a new instance of Exporter.
17 18 19 20 |
# File 'lib/exportable/export_methods/xls_exporter.rb', line 17 def initialize(model) @book = Spreadsheet::Workbook.new @model = model end |
Instance Method Details
#export(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/exportable/export_methods/xls_exporter.rb', line 22 def export() sheet = @book.create_worksheet i = 0 if [:header] sheet.row(i).concat([:fields].map(&:to_s)) i += 1 end @model.where(nil).find_each do |record| sheet.row(i).concat [:fields].map { |attr| record.send(attr).to_s } i += 1 end write_io_output end |
#write_io_output ⇒ Object
36 37 38 39 40 |
# File 'lib/exportable/export_methods/xls_exporter.rb', line 36 def write_io_output output = StringIO.new @book.write output output.string end |