Sha256: 9b24859d1c7a7d05c2a0bd0cdf8560591568914e3bf3a217de3514d5531e7375

Contents?: true

Size: 1.79 KB

Versions: 17

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    module Import
      module Readers
        # Abstract class with a very naive default implementation. Each importable
        # file type should have it is own reader.
        class Base
          # Defines which index of the records defines the first line of actual
          # data. E.g. with spreadsheet formats, the first row contains column
          # name information.
          def self.first_data_index
            0
          end

          def initialize(file)
            @file = file
          end

          # The read_rows method should iterate over each row of the data and
          # yield the data array of each row with the row's index.
          # The first row yielded with index 0 needs to contain the data headers
          # which can be later used to map the data to correct attributes.
          #
          # This needs to be implemented by the extending classes.
          #
          # Returns an array of the import data where the first row should
          # contain the columns.
          def read_rows
            raise NotImplementedError
          end

          # The example_file should produce an example data file for the user to
          # download and take example from to produce their import files. The
          # data provided for the example file generation should be the same as
          # what is returned by the read_rows method.
          #
          # _data - An array of data to produce the file from
          #
          # Returns an IO stream that can be saved to a file or sent to the
          # browser to produce the import file.
          def example_file(_data)
            raise NotImplementedError
          end

          protected

          attr_reader :file
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-admin-0.30.0.rc2 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.30.0.rc1 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.29.2 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.5 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.29.1 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.4 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.29.0 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.3 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.29.0.rc4 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.29.0.rc3 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.29.0.rc2 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.29.0.rc1 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.2 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.1 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.0 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.0.rc5 lib/decidim/admin/import/readers/base.rb
decidim-admin-0.28.0.rc4 lib/decidim/admin/import/readers/base.rb