Class: UpdateParallelStudents

Inherits:
Object
  • Object
show all
Includes:
Interpipe::Interactor
Defined in:
app/interactors/update_parallel_students.rb

Instance Method Summary collapse

Methods included from Interpipe::Interactor

included, #initialize

Instance Method Details

#convert_student(student) ⇒ Object


22
23
24
25
26
27
28
# File 'app/interactors/update_parallel_students.rb', line 22

def convert_student(student)
  student_id = get_student_id(student)
  @students[student_id] ||= Person.new do |p|
    p.id = student_id
    p.full_name = student.full_name
  end
end

#get_student_id(student) ⇒ Object


34
35
36
# File 'app/interactors/update_parallel_students.rb', line 34

def get_student_id(student)
  student.username || student.personal_number
end

#perform(students:) ⇒ Object


11
12
13
14
15
16
# File 'app/interactors/update_parallel_students.rb', line 11

def perform(students:)
  students.each do |parallel, parallel_students|
    parallel.student_ids = process_students(parallel_students)
    parallel.save
  end
end

#process_students(students) ⇒ Object


18
19
20
# File 'app/interactors/update_parallel_students.rb', line 18

def process_students(students)
  students.map { |student| convert_student(student).id }
end

#resultsObject


30
31
32
# File 'app/interactors/update_parallel_students.rb', line 30

def results
  { people: @students.values }
end

#setupObject


7
8
9
# File 'app/interactors/update_parallel_students.rb', line 7

def setup
  @students = {}
end