Class: Course::Assessment::Question::TextResponse

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

Instance Method Summary collapse

Instance Method Details

#attempt(submission, last_attempt = nil) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/course/assessment/question/text_response.rb', line 55

def attempt(submission, last_attempt = nil)
  answer =
    Course::Assessment::Answer::TextResponse.new(submission: submission, question: question)
  if last_attempt
    answer.answer_text = last_attempt.answer_text
    if last_attempt.attachment_references.any?
      answer.attachment_references = last_attempt.attachment_references.map(&:dup)
    end
  end
  answer.acting_as
end

#auto_gradable?Boolean

Returns:

  • (Boolean)

17
18
19
20
21
22
23
# File 'app/models/course/assessment/question/text_response.rb', line 17

def auto_gradable?
  if comprehension_question?
    groups.any?(&:auto_gradable_group?)
  else
    !solutions.empty?
  end
end

#auto_graderObject


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

def auto_grader
  if comprehension_question?
    Course::Assessment::Answer::TextResponseComprehensionAutoGradingService.new
  else
    Course::Assessment::Answer::TextResponseAutoGradingService.new
  end
end

#build_at_least_one_group_one_pointObject


82
83
84
85
# File 'app/models/course/assessment/question/text_response.rb', line 82

def build_at_least_one_group_one_point
  groups.build if groups.empty?
  groups.first.points.build if groups.first.points.empty?
end

#comprehension_question?Boolean

Method provides readability to identifying whether a question is a (GCE A-Level General Paper) comprehension question.

Returns:

  • (Boolean)

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

def comprehension_question?
  is_comprehension
end

#downloadable?Boolean

Returns:

  • (Boolean)

67
68
69
# File 'app/models/course/assessment/question/text_response.rb', line 67

def downloadable?
  true
end

#file_upload_question?Boolean

Method provides readability to identifying whether a question is a file upload question. Used with the front-end translations.

Returns:

  • (Boolean)

27
28
29
# File 'app/models/course/assessment/question/text_response.rb', line 27

def file_upload_question?
  hide_text
end

#initialize_duplicate(duplicator, other) ⇒ Object


71
72
73
74
75
76
77
78
79
80
# File 'app/models/course/assessment/question/text_response.rb', line 71

def initialize_duplicate(duplicator, other)
  copy_attributes(other)
  associate_duplicated_skills(duplicator, other)

  if comprehension_question?
    self.groups = duplicator.duplicate(other.groups)
  else
    self.solutions = duplicator.duplicate(other.solutions)
  end
end

#question_typeObject


37
38
39
40
41
42
43
44
45
# File 'app/models/course/assessment/question/text_response.rb', line 37

def question_type
  if file_upload_question?
    I18n.t('activerecord.attributes.models.course/assessment/question/text_response.file_upload')
  elsif comprehension_question?
    I18n.t('activerecord.attributes.models.course/assessment/question/text_response.comprehension')
  else
    I18n.t('activerecord.attributes.models.course/assessment/question/text_response.text_response')
  end
end