Class: Decidim::Admin::Import::Readers::Base
- Inherits:
-
Object
- Object
- Decidim::Admin::Import::Readers::Base
- Defined in:
- lib/decidim/admin/import/readers/base.rb
Overview
Abstract class with a very naive default implementation. Each importable file type should have it’s own reader.
Class Method Summary collapse
-
.first_data_index ⇒ Object
Defines which index of the records defines the first line of actual data.
Instance Method Summary collapse
-
#example_file(_data) ⇒ Object
The example_file should produce an example data file for the user to download and take example from to produce their import files.
-
#initialize(file) ⇒ Base
constructor
A new instance of Base.
-
#read_rows ⇒ Object
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.
Constructor Details
#initialize(file) ⇒ Base
Returns a new instance of Base.
17 18 19 |
# File 'lib/decidim/admin/import/readers/base.rb', line 17 def initialize(file) @file = file end |
Class Method Details
.first_data_index ⇒ Object
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.
13 14 15 |
# File 'lib/decidim/admin/import/readers/base.rb', line 13 def self.first_data_index 0 end |
Instance Method Details
#example_file(_data) ⇒ Object
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.
43 44 45 |
# File 'lib/decidim/admin/import/readers/base.rb', line 43 def example_file(_data) raise NotImplementedError end |
#read_rows ⇒ Object
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.
30 31 32 |
# File 'lib/decidim/admin/import/readers/base.rb', line 30 def read_rows raise NotImplementedError end |