Class: MakeExportable::CSV

Inherits:
ExportableFormat show all
Defined in:
lib/make_exportable/exportable_formats/csv.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from ExportableFormat

#long, #mime_type

Instance Method Summary collapse

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_headersObject

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_setObject

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

#generateObject



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