Class: Gaku::Importers::Students::Csv
- Inherits:
-
Object
- Object
- Gaku::Importers::Students::Csv
- Includes:
- StudentIdentity
- Defined in:
- lib/gaku/importers/students/csv.rb
Instance Attribute Summary collapse
-
#csv ⇒ Object
readonly
Returns the value of attribute csv.
-
#import_file_id ⇒ Object
readonly
Returns the value of attribute import_file_id.
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(import_file_id, path) ⇒ Csv
constructor
A new instance of Csv.
Methods included from StudentIdentity
#find_student_by_student_ids, #normalize_id_num
Constructor Details
#initialize(import_file_id, path) ⇒ Csv
Returns a new instance of Csv.
7 8 9 10 |
# File 'lib/gaku/importers/students/csv.rb', line 7 def initialize(import_file_id, path) @import_file_id = import_file_id @csv = SmarterCSV.process(path) end |
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
5 6 7 |
# File 'lib/gaku/importers/students/csv.rb', line 5 def csv @csv end |
#import_file_id ⇒ Object (readonly)
Returns the value of attribute import_file_id.
5 6 7 |
# File 'lib/gaku/importers/students/csv.rb', line 5 def import_file_id @import_file_id end |
Instance Method Details
#import ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gaku/importers/students/csv.rb', line 12 def import cleanup_student_states enrollment_status_code = Gaku::EnrollmentStatus.where(code: 'enrolled', active: true, immutable: true) .first_or_create!.try(:code) ActiveRecord::Base.transaction do @csv.each do |row| next if student_record(row) student = Gaku::Student.new(filter_row(row)) student.enrollment_status_code = enrollment_status_code if student.save $redis.rpush "import_file:#{@import_file_id}:created", student.id else $redis.rpush "import_file:#{@import_file_id}:not_saved", not_saved_students(student) end end end end |