Class: Decidim::Exporters::ExportData

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/exporters/export_data.rb

Overview

Holds the result of an export.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, extension) ⇒ ExportData

Initializes an ‘ExportData` with the RAW data and the extension.



10
11
12
13
# File 'lib/decidim/exporters/export_data.rb', line 10

def initialize(data, extension)
  @data = data
  @extension = extension
end

Instance Attribute Details

#extensionObject (readonly)

Returns the value of attribute extension.



7
8
9
# File 'lib/decidim/exporters/export_data.rb', line 7

def extension
  @extension
end

Instance Method Details

#filename(prefix = "export", options = {}) ⇒ Object

Generates a filename based on the export creation date.

prefix - A string value for the filename prefix. (default: ‘export’) options - An optional hash of options

* extension - Whether the filename should include the extension or not.

Returns a String with the filename of the export.



29
30
31
32
33
34
# File 'lib/decidim/exporters/export_data.rb', line 29

def filename(prefix = "export", options = {})
  options[:extension] = options[:extension].nil? ? true : options[:extension]
  result = "#{prefix}-#{I18n.l(Time.zone.today, format: :default)}-#{Time.now.seconds_since_midnight.to_i}"
  result += ".#{extension}" if options[:extension]
  result
end

#readObject

Gives back the raw data of the export.

Returns a String with the result of the export.



18
19
20
# File 'lib/decidim/exporters/export_data.rb', line 18

def read
  @data
end