Class: ActiveList::Exporters::AbstractExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_list/exporters/abstract_exporter.rb

Direct Known Subclasses

CsvExporter, OpenDocumentSpreadsheetExporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator) ⇒ AbstractExporter

Returns a new instance of AbstractExporter.



9
10
11
12
# File 'lib/active_list/exporters/abstract_exporter.rb', line 9

def initialize(generator)
  @generator = generator
  @table = generator.table
end

Instance Attribute Details

#generatorObject (readonly)

Returns the value of attribute generator.



7
8
9
# File 'lib/active_list/exporters/abstract_exporter.rb', line 7

def generator
  @generator
end

#tableObject (readonly)

Returns the value of attribute table.



7
8
9
# File 'lib/active_list/exporters/abstract_exporter.rb', line 7

def table
  @table
end

Instance Method Details

#columns_headers(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/active_list/exporters/abstract_exporter.rb', line 26

def columns_headers(options={})
  headers, columns = [], table.exportable_columns
  for column in columns
    datum = column.header_code
    headers << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}')" : datum)
  end
  return headers
end

#columns_to_array(nature, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/active_list/exporters/abstract_exporter.rb', line 35

def columns_to_array(nature, options={})
  columns = table.exportable_columns

  array = []
  record = options[:record] || 'record_of_the_death'
  for column in columns
    if column.is_a?(ActiveList::Definition::AbstractColumn)
      if nature == :header
        datum = column.header_code
      else
        datum = column.exporting_datum_code(record)
      end
      array << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}')" : datum)
    end
  end
  return array
end

#file_extensionObject



14
15
16
# File 'lib/active_list/exporters/abstract_exporter.rb', line 14

def file_extension
  "txt"
end

#mime_typeObject



18
19
20
# File 'lib/active_list/exporters/abstract_exporter.rb', line 18

def mime_type
  Mime::TEXT
end

#send_data_codeObject

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/active_list/exporters/abstract_exporter.rb', line 22

def send_data_code
  raise NotImplementedError, "#{self.class.name}#format_data_code is not implemented."
end