Class: Course::Assessment::Question::ScribingImportService

Inherits:
Object
  • Object
show all
Defined in:
app/services/course/assessment/question/scribing_import_service.rb

Overview

Imports new pdf files, splits and processes the files and creates scribing questions for each page of the PDF file.

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ ScribingImportService

Creates a new service import object.


8
9
10
11
# File 'app/services/course/assessment/question/scribing_import_service.rb', line 8

def initialize(params)
  @params = params[:question_scribing]
  @assessment_id = params[:assessment_id]
end

Instance Method Details

#saveBoolean

Imports and saves the provided PDF as a scribing question.

Returns:

  • (Boolean)

    True if the pdf is processed and successfully saved, otherwise false. Note that if the save is unsuccessful, all questions are not persisted.


17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/course/assessment/question/scribing_import_service.rb', line 17

def save
  return_value = true
  Course::Assessment::Question::Scribing.transaction do
    build_scribing_questions(generate_pdf_files).each do |question|
      unless question.save
        return_value = false
        raise ActiveRecord::Rollback
      end
    end
  end
  return_value
end