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.



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

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

Instance Attribute Details

#generatorObject (readonly)

Returns the value of attribute generator.



4
5
6
# File 'lib/active_list/exporters/abstract_exporter.rb', line 4

def generator
  @generator
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/active_list/exporters/abstract_exporter.rb', line 4

def table
  @table
end

Instance Method Details

#columns_headers(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/active_list/exporters/abstract_exporter.rb', line 23

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]}', invalid: :replace, undef: :replace)" : datum)
  end
  headers
end

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



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

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

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

#file_extensionObject



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

def file_extension
  'txt'
end

#mime_typeObject



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

def mime_type
  Mime::TEXT
end

#send_data_codeObject

Raises:

  • (NotImplementedError)


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

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