Class: CsvImportMagic::Importer
- Inherits:
-
Object
- Object
- CsvImportMagic::Importer
- Defined in:
- app/services/csv_import_magic/importer.rb
Instance Attribute Summary collapse
-
#csv_parser_class ⇒ Object
readonly
Returns the value of attribute csv_parser_class.
-
#importer ⇒ Object
readonly
Returns the value of attribute importer.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#source_klass ⇒ Object
readonly
Returns the value of attribute source_klass.
Instance Method Summary collapse
- #call ⇒ Object
- #column_separator ⇒ Object
-
#initialize(importer_id, resources = nil) ⇒ Importer
constructor
A new instance of Importer.
Constructor Details
#initialize(importer_id, resources = nil) ⇒ Importer
Returns a new instance of Importer.
5 6 7 8 9 10 11 |
# File 'app/services/csv_import_magic/importer.rb', line 5 def initialize(importer_id, resources = nil) @importer = ::Importer.find(importer_id) @source_klass = importer.source_klass @csv_parser_class = importer.parser_klass @resources = resources.try(:symbolize_keys!) @model = model_with_relation || @source_klass end |
Instance Attribute Details
#csv_parser_class ⇒ Object (readonly)
Returns the value of attribute csv_parser_class.
3 4 5 |
# File 'app/services/csv_import_magic/importer.rb', line 3 def csv_parser_class @csv_parser_class end |
#importer ⇒ Object (readonly)
Returns the value of attribute importer.
3 4 5 |
# File 'app/services/csv_import_magic/importer.rb', line 3 def importer @importer end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
3 4 5 |
# File 'app/services/csv_import_magic/importer.rb', line 3 def resources @resources end |
#source_klass ⇒ Object (readonly)
Returns the value of attribute source_klass.
3 4 5 |
# File 'app/services/csv_import_magic/importer.rb', line 3 def source_klass @source_klass end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 |
# File 'app/services/csv_import_magic/importer.rb', line 13 def call csv_parsed.run! csv_parsed.report csv_parsed end |
#column_separator ⇒ Object
19 20 21 22 |
# File 'app/services/csv_import_magic/importer.rb', line 19 def column_separator header = content.lines("\r")[0].gsub(/[^,;\t]/, '_') header.scan(/[,;\t]/).first end |