Class: StandardImporter
- Inherits:
-
Object
- Object
- StandardImporter
- Defined in:
- lib/standard_importer.rb
Overview
Import standards from db/data/standards_*.csv files
Instance Method Summary collapse
-
#initialize(subject) ⇒ StandardImporter
constructor
A new instance of StandardImporter.
- #run ⇒ Object
Constructor Details
#initialize(subject) ⇒ StandardImporter
Returns a new instance of StandardImporter.
8 9 10 11 12 |
# File 'lib/standard_importer.rb', line 8 def initialize(subject) @subject = subject.to_s @source_file = "db/data/standards_#{subject}.csv" raise 'Source file not found!' unless File.exist?(@source_file) end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 |
# File 'lib/standard_importer.rb', line 14 def run content = File.read source_file ActiveRecord::Base.transaction do CSV.parse(content, headers: true) { |row| import row } end end |