Module: Effective::EffectiveDatatable::Csv
- Included in:
- Datatable
- Defined in:
- app/models/effective/effective_datatable/csv.rb
Instance Method Summary collapse
- #csv_content_type ⇒ Object
- #csv_file ⇒ Object
- #csv_filename ⇒ Object
- #csv_header ⇒ Object
- #csv_stream ⇒ Object
Instance Method Details
#csv_content_type ⇒ Object
13 14 15 |
# File 'app/models/effective/effective_datatable/csv.rb', line 13 def csv_content_type 'text/csv; charset=utf-8' end |
#csv_file ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/effective/effective_datatable/csv.rb', line 21 def csv_file CSV.generate do |csv| csv << csv_header() collection.send(csv_collection_method) do |resources| resources = arrayize(resources, csv: true) format(resources, csv: true) finalize(resources) resources.each { |resource| csv << resource } end end end |
#csv_filename ⇒ Object
9 10 11 |
# File 'app/models/effective/effective_datatable/csv.rb', line 9 def csv_filename self.class.name.underscore.parameterize + '.csv' end |
#csv_header ⇒ Object
17 18 19 |
# File 'app/models/effective/effective_datatable/csv.rb', line 17 def csv_header columns.map { |_, opts| opts[:label] || '' } end |
#csv_stream ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/effective/effective_datatable/csv.rb', line 35 def csv_stream EffectiveResources.with_resource_enumerator do |lines| lines << CSV.generate_line(csv_header) collection.public_send(csv_collection_method) do |resources| resources = arrayize(resources, csv: true) format(resources, csv: true) finalize(resources) resources.each { |resource| lines << CSV.generate_line(resource) } end end end |