Class: RailsAdminImport::Formats::CSVImporter
- Inherits:
-
FileImporter
- Object
- FileImporter
- RailsAdminImport::Formats::CSVImporter
- Defined in:
- lib/rails_admin_import/formats/csv_importer.rb
Constant Summary collapse
- HEADER_CONVERTER =
Default is to downcase headers and add underscores to convert into attribute names
lambda do |header| header.parameterize.underscore end
Instance Attribute Summary
Attributes inherited from FileImporter
#error, #filename, #import_model
Instance Method Summary collapse
-
#each_record ⇒ Object
A method that yields a hash of attributes for each record to import.
-
#initialize(import_model, params) ⇒ CSVImporter
constructor
A new instance of CSVImporter.
Methods inherited from FileImporter
Constructor Details
#initialize(import_model, params) ⇒ CSVImporter
Returns a new instance of CSVImporter.
14 15 16 17 18 |
# File 'lib/rails_admin_import/formats/csv_importer.rb', line 14 def initialize(import_model, params) super @encoding = params[:encoding] @header_converter = RailsAdminImport.config.header_converter || HEADER_CONVERTER end |
Instance Method Details
#each_record ⇒ Object
A method that yields a hash of attributes for each record to import
21 22 23 24 25 |
# File 'lib/rails_admin_import/formats/csv_importer.rb', line 21 def each_record CSV.foreach(filename, ) do |row| yield convert_to_attributes(row) end end |