Class: Para::Importer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/para/importer/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#sheetObject (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

#runObject



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