Class: MakeExportable::CSV
- Inherits:
-
ExportableFormat
- Object
- ExportableFormat
- MakeExportable::CSV
- Defined in:
- lib/make_exportable/exportable_formats/csv.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#data_headers ⇒ Object
Returns the value of attribute data_headers.
-
#data_set ⇒ Object
Returns the value of attribute data_set.
Attributes inherited from ExportableFormat
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(data_set, data_headers = []) ⇒ CSV
constructor
A new instance of CSV.
Methods inherited from ExportableFormat
#generate_header_option, register_format, #sanitize
Constructor Details
#initialize(data_set, data_headers = []) ⇒ CSV
Returns a new instance of CSV.
17 18 19 20 21 22 |
# File 'lib/make_exportable/exportable_formats/csv.rb', line 17 def initialize(data_set, data_headers=[]) self.long = 'Comma-separated (CSV)' self.mime_type = 'text/csv; charset=utf-8;' self.data_set = data_set self.data_headers = data_headers end |
Instance Attribute Details
#data_headers ⇒ Object
Returns the value of attribute data_headers.
15 16 17 |
# File 'lib/make_exportable/exportable_formats/csv.rb', line 15 def data_headers @data_headers end |
#data_set ⇒ Object
Returns the value of attribute data_set.
15 16 17 |
# File 'lib/make_exportable/exportable_formats/csv.rb', line 15 def data_set @data_set end |
Instance Method Details
#generate ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/make_exportable/exportable_formats/csv.rb', line 25 def generate generate_header_option(data_headers) @@csv_type.generate do |csv| csv << data_headers.map {|h| sanitize(h.humanize.titleize)} unless data_headers.blank? data_set.each {|row| csv << row } end end |