Class: CanvasQtiToLearnosityConverter::FillTheBlanksQuestion

Inherits:
Object
  • Object
show all
Defined in:
lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb

Overview

Canvas New Quizzes combines typed-text blanks (openEntry), dropdown menus, and word banks all under the single fill_in_multiple_blanks_question QTI type. Since Learnosity requires a distinct question type for each interaction style, this class acts as a dispatcher: it inspects the answer_type attributes on the response_labels and returns the appropriate subclass instance.

Class Method Summary collapse

Class Method Details

.for(xml) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb', line 17

def self.for(xml)
  types = xml.css("item > presentation > response_lid").map do |lid|
    first_label = lid.css("render_choice > response_label").first
    case first_label&.attribute("answer_type")&.value
    when "dropdown" then :dropdown
    when "wordbank" then :wordbank
    else                 :blank
    end
  end.uniq

  raise MixedFillBlanksTypeError if types.size > 1

  case types.first
  when :dropdown then FillBlanksDropdownQuestion.new(xml)
  when :wordbank  then FillBlanksWordBankQuestion.new(xml)
  else                 FillBlanksTextQuestion.new(xml)
  end
end