Sha256: a363ebc65ea8f0b51d7740f53f3792930bdd9daf7e59b8fd627402c96c5d11db

Contents?: true

Size: 1.16 KB

Versions: 54

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Decidim
  module Exporters
    # Holds the result of an export.
    class ExportData
      attr_reader :extension

      # Initializes an `ExportData` with the RAW data and the extension.
      def initialize(data, extension)
        @data = data
        @extension = extension
      end

      # Gives back the raw data of the export.
      #
      # Returns a String with the result of the export.
      def read
        @data
      end

      # 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.
      def filename(prefix = "export", options = {})
        options[:extension] = !options[:extension].nil? ? options[:extension] : true
        result = "#{prefix}-#{I18n.localize(Time.zone.today, format: :default)}-#{Time.now.seconds_since_midnight.to_i}"
        result += ".#{extension}" if options[:extension]
        result
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
decidim-core-0.23.6 lib/decidim/exporters/export_data.rb
decidim-core-0.23.5 lib/decidim/exporters/export_data.rb
decidim-core-0.23.4 lib/decidim/exporters/export_data.rb
decidim-core-0.23.3 lib/decidim/exporters/export_data.rb
decidim-core-0.23.2 lib/decidim/exporters/export_data.rb
decidim-core-0.23.1 lib/decidim/exporters/export_data.rb
decidim-core-0.23.1.rc1 lib/decidim/exporters/export_data.rb
decidim-core-0.23.0 lib/decidim/exporters/export_data.rb
decidim-core-0.22.0 lib/decidim/exporters/export_data.rb
decidim-core-0.21.0 lib/decidim/exporters/export_data.rb
decidim-core-0.20.1 lib/decidim/exporters/export_data.rb
decidim-core-0.20.0 lib/decidim/exporters/export_data.rb
decidim-core-0.19.1 lib/decidim/exporters/export_data.rb
decidim-core-0.18.1 lib/decidim/exporters/export_data.rb
decidim-core-0.19.0 lib/decidim/exporters/export_data.rb
decidim-core-0.17.2 lib/decidim/exporters/export_data.rb
decidim-core-0.18.0 lib/decidim/exporters/export_data.rb
decidim-core-0.17.1 lib/decidim/exporters/export_data.rb
decidim-core-0.16.1 lib/decidim/exporters/export_data.rb
decidim-core-0.17.0 lib/decidim/exporters/export_data.rb