Class: StandardImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/standard_importer.rb

Overview

Import standards from db/data/standards_*.csv files

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ StandardImporter

Returns a new instance of StandardImporter.

Parameters:

  • subject (String)

    Should be ‘math` or `ela`



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

#runObject



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