Class: Course::Assessment::Question

Inherits:
ApplicationRecord show all
Defined in:
app/models/course/assessment/question.rb

Defined Under Namespace

Modules: ProgrammingHelper Classes: AnswersEvaluationJob, AnswersEvaluationService, Controller, MultipleResponse, MultipleResponseOption, MultipleResponsesController, Programming, ProgrammingController, ProgrammingImportJob, ProgrammingImportService, ProgrammingTemplateFile, ProgrammingTestCase, Scribing, ScribingController, ScribingImportService, TextResponse, TextResponseComprehensionGroup, TextResponseComprehensionPoint, TextResponseComprehensionSolution, TextResponseLemmaService, TextResponseSolution, TextResponsesController, VoiceResponse, VoiceResponsesController

Instance Method Summary collapse

Instance Method Details

#associate_duplicated_skills(duplicator, other) ⇒ Object

Associates duplicated skills with the current question


84
85
86
87
88
# File 'app/models/course/assessment/question.rb', line 84

def associate_duplicated_skills(duplicator, other)
  skills << other.skills.
            select { |skill| duplicator.duplicated?(skill) }.
            map { |skill| duplicator.duplicate(skill) }
end

#attempt(submission, last_attempt = nil) ⇒ Course::Assessment::Answer

Attempts the given question in the submission. This builds a new answer for the current question.

Parameters:

Returns:

  • (Course::Assessment::Answer)

    The answer corresponding to the question. It is required that the Answer#question property be the same as +self+. The result should not be persisted.

Raises:

  • (NotImplementedError)

    question#attempt was not implemented.


48
49
50
51
52
53
# File 'app/models/course/assessment/question.rb', line 48

def attempt(submission, last_attempt = nil)
  if actable&.self_respond_to?(:attempt)
    return actable.attempt(submission, last_attempt ? last_attempt.actable : nil)
  end
  raise NotImplementedError, 'Questions must implement the #attempt method for submissions.'
end

#auto_gradable?Boolean

Checks if the given question is auto gradable. This defaults to false if the specific question does not implement auto grading. If this returns true, +auto_grader+ is guaranteed to return a valid grader service.

Different instances of a question can have different auto gradability.

Returns:

  • (Boolean)

    True if the question supports auto grading.


24
25
26
# File 'app/models/course/assessment/question.rb', line 24

def auto_gradable?
  actable.present? && actable.self_respond_to?(:auto_gradable?) ? actable.auto_gradable? : false
end

#auto_graderCourse::Assessment::Answer::AutoGradingService

Gets an instance of the auto grader suitable for use with this question.

Returns:

Raises:

  • (NotImplementedError)

    The question does not have a suitable auto grader for use.


32
33
34
35
# File 'app/models/course/assessment/question.rb', line 32

def auto_grader
  raise NotImplementedError unless auto_gradable? && actable.self_respond_to?(:auto_grader)
  actable.auto_grader || (raise NotImplementedError)
end

#copy_attributes(other) ⇒ Object

Copy attributes for question from the object being duplicated.

Parameters:

  • other (Object)

    The source object to copy attributes from.


76
77
78
79
80
81
# File 'app/models/course/assessment/question.rb', line 76

def copy_attributes(other)
  self.title = other.title
  self.description = other.description
  self.staff_only_comments = other.staff_only_comments
  self.maximum_grade = other.maximum_grade
end

#downloadable?Boolean

Whether the answer has downloadable content.

Returns:

  • (Boolean)

65
66
67
68
69
70
71
# File 'app/models/course/assessment/question.rb', line 65

def downloadable?
  if actable.self_respond_to?(:downloadable?)
    actable.downloadable?
  else
    false
  end
end

#last_question?Boolean

Test if the question is the last question of the assessment.

Returns:

  • (Boolean)

    True if the question is the last question, otherwise False.


58
59
60
# File 'app/models/course/assessment/question.rb', line 58

def last_question?
  assessment.questions.last == self
end