Sha256: 568457525e3d1156b1526ddddeb8672189cc90746c52c38e98c6ca2123ce383c

Contents?: true

Size: 1.15 KB

Versions: 18

Compression:

Stored size: 1.15 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(Date.today, format: :default)}-#{Time.now.seconds_since_midnight.to_i}"
        result += ".#{extension}" if options[:extension]
        result
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
decidim-core-0.6.8 lib/decidim/exporters/export_data.rb
decidim-0.6.8 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.7 lib/decidim/exporters/export_data.rb
decidim-0.6.7 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.6 lib/decidim/exporters/export_data.rb
decidim-0.6.6 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.5 lib/decidim/exporters/export_data.rb
decidim-0.6.5 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.4 lib/decidim/exporters/export_data.rb
decidim-0.6.4 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.3 lib/decidim/exporters/export_data.rb
decidim-0.6.3 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.2 lib/decidim/exporters/export_data.rb
decidim-0.6.2 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.1 lib/decidim/exporters/export_data.rb
decidim-0.6.1 decidim-core/lib/decidim/exporters/export_data.rb
decidim-core-0.6.0 lib/decidim/exporters/export_data.rb
decidim-0.6.0 decidim-core/lib/decidim/exporters/export_data.rb