Class: Para::Importer::Base
- Inherits:
-
Object
- Object
- Para::Importer::Base
- Defined in:
- lib/para/importer/base.rb
Instance Attribute Summary collapse
-
#sheet ⇒ Object
readonly
Returns the value of attribute sheet.
Instance Method Summary collapse
- #import_from_row(row) ⇒ Object
-
#initialize(file) ⇒ Base
constructor
A new instance of Base.
- #run ⇒ Object
Constructor Details
#initialize(file) ⇒ Base
Returns a new instance of Base.
6 7 8 |
# File 'lib/para/importer/base.rb', line 6 def initialize(file) @sheet = Roo::Spreadsheet.open(file.path) end |
Instance Attribute Details
#sheet ⇒ Object (readonly)
Returns the value of attribute sheet.
4 5 6 |
# File 'lib/para/importer/base.rb', line 4 def sheet @sheet end |
Instance Method Details
#import_from_row(row) ⇒ Object
18 19 20 |
# File 'lib/para/importer/base.rb', line 18 def import_from_row(row) raise '#import_from_row(row) must be defined' end |
#run ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/para/importer/base.rb', line 10 def run ActiveRecord::Base.transaction do (2..(sheet.last_row)).each do |index| import_from_row(sheet.row(index)) end end end |