Class: Smuggle::Importer::Base
- Inherits:
-
Object
- Object
- Smuggle::Importer::Base
- Defined in:
- lib/smuggle/importer/base.rb
Direct Known Subclasses
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(row, model) ⇒ Base
constructor
A new instance of Base.
- #persist ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(row, model) ⇒ Base
Returns a new instance of Base.
28 29 30 31 |
# File 'lib/smuggle/importer/base.rb', line 28 def initialize(row, model) @model = model @row = row end |
Class Attribute Details
.attributes(*names) ⇒ Object
13 14 15 |
# File 'lib/smuggle/importer/base.rb', line 13 def attributes(*names) @attributes.concat names end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
26 27 28 |
# File 'lib/smuggle/importer/base.rb', line 26 def model @model end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
26 27 28 |
# File 'lib/smuggle/importer/base.rb', line 26 def row @row end |
Class Method Details
.attributes? ⇒ Boolean
17 18 19 |
# File 'lib/smuggle/importer/base.rb', line 17 def attributes? @attributes.any? end |
.csv_converters ⇒ Object
21 22 23 |
# File 'lib/smuggle/importer/base.rb', line 21 def csv_converters Hash(header_converters: :symbol, converters: %i[all]) end |
.inherited(subclass) ⇒ Object
9 10 11 |
# File 'lib/smuggle/importer/base.rb', line 9 def inherited(subclass) subclass.attributes = [] end |
Instance Method Details
#persist ⇒ Object
33 34 35 |
# File 'lib/smuggle/importer/base.rb', line 33 def persist raise NotImplementedError end |
#to_h ⇒ Object
37 38 39 40 41 |
# File 'lib/smuggle/importer/base.rb', line 37 def to_h defined_attributes.each_with_object({}) do |attribute, hash| hash[attribute.to_sym] = respond_to?(attribute) ? public_send(attribute) : row[attribute.to_sym] end end |