Class: ConvertExams

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

Instance Method Summary collapse

Methods included from Interpipe::Interactor

included, #initialize, #setup

Instance Method Details

#convert_exam(exam) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/interactors/convert_exams.rb', line 19

def convert_exam(exam)
  ImportedExam.played_by(exam) do |exam|
    Event.new(
      starts_at: exam.start_date,
      ends_at: exam.end_date,
      course_id: exam.course.link_id,
      teacher_ids: [],
      capacity: exam.capacity,
      event_type: exam.event_type,
      absolute_sequence_number: 1,
      source_type: 'exam',
      source_id: exam.link.link_id,
      semester: @faculty_semester.code,
      faculty: @faculty_semester.faculty
    ).tap do |event|
      event.room_id = exam.room.link_id if exam.room
      if exam.examiner
        event.teacher_ids = [exam.examiner.link_id]
      elsif exam.examiners
        event.teacher_ids = exam.examiners.map(&:link_id)
      end
      event.note = {cs: exam.note} if exam.note
    end
  end
end

#perform(exams:, faculty_semester:, **args) ⇒ Object


9
10
11
12
13
# File 'app/interactors/convert_exams.rb', line 9

def perform(exams:, faculty_semester:, **args)
  @exams = exams
  @faculty_semester = faculty_semester
  @events = exams.map { |exam| convert_exam(exam) }
end

#resultsObject


15
16
17
# File 'app/interactors/convert_exams.rb', line 15

def results
  { events: @events, exams: @exams }
end