Class: Excelsieur::Import
- Inherits:
-
Object
- Object
- Excelsieur::Import
- Includes:
- Mapping, Source, Transaction
- Defined in:
- lib/excelsieur/import.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#result ⇒ Object
Returns the value of attribute result.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(file = nil) ⇒ Import
constructor
A new instance of Import.
- #run(&block) ⇒ Object
Methods included from Transaction
Methods included from Mapping
Methods included from Source
Constructor Details
#initialize(file = nil) ⇒ Import
Returns a new instance of Import.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/excelsieur/import.rb', line 22 def initialize(file = nil) self.source = file || self.class.source_file self.fields = self.class.fields @doc = ::SimpleXlsxReader.open(source) @sheet = @doc.sheets.first @columns = @sheet.rows.shift @rows = @sheet.rows @result = Result.new(@rows.length) end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
19 20 21 |
# File 'lib/excelsieur/import.rb', line 19 def columns @columns end |
#fields ⇒ Object
Returns the value of attribute fields.
19 20 21 |
# File 'lib/excelsieur/import.rb', line 19 def fields @fields end |
#result ⇒ Object
Returns the value of attribute result.
19 20 21 |
# File 'lib/excelsieur/import.rb', line 19 def result @result end |
#rows ⇒ Object
Returns the value of attribute rows.
19 20 21 |
# File 'lib/excelsieur/import.rb', line 19 def rows @rows end |
#source ⇒ Object
Returns the value of attribute source.
19 20 21 |
# File 'lib/excelsieur/import.rb', line 19 def source @source end |
Instance Method Details
#run(&block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/excelsieur/import.rb', line 35 def run(&block) check_columns! return if result.failed? if self.class.use_transaction run_with_transaction(&block) else insert_rows(&block) end result end |