Class: CanvasQtiToLearnosityConverter::MultipleChoiceQuestion

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

Direct Known Subclasses

MultipleAnswersQuestion

Instance Method Summary collapse

Methods inherited from QuizQuestion

#convert, #dynamic_content_data, #extract_mattext, #extract_points_possible, #extract_stimulus, #initialize, #make_identifier, #process_assets!

Constructor Details

This class inherits a constructor from CanvasQtiToLearnosityConverter::QuizQuestion

Instance Method Details

#add_learnosity_assets(assets, path, learnosity) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 49

def add_learnosity_assets(assets, path, learnosity)
  process_assets!(
    assets,
    path,
    learnosity[:stimulus]
  )

  learnosity[:options].each.with_index do |option, index|
    process_assets!(
      assets,
      path,
      option["label"]
    )
  end
  learnosity
end

#extract_optionsObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 5

def extract_options()
  choices = @xml.css("item > presentation > response_lid > render_choice > response_label")
  choices.map do |choice|
    ident = choice.attribute("ident").value
    {
      "value" => ident,
      "label" => extract_mattext(choice.css("material > mattext").first),
    }
  end
end

#extract_response_idObject



16
17
18
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 16

def extract_response_id()
  @xml.css("item > presentation > response_lid").attribute("ident").value
end

#extract_validationObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 20

def extract_validation()
  resp_conditions = @xml.css("item > resprocessing > respcondition")
  correct_condition = resp_conditions.select do |condition|
    setvar = condition.css("setvar")
    setvar.length === 1 && setvar.text === "100"
  end.first

  # TODO check for more than 1 element
  correct_value = correct_condition.css("varequal").text
  {
    "scoring_type" => "exactMatch",
    "valid_response" => {
      "value" => [correct_value],
      "score" => extract_points_possible,
    },
  }
end

#to_learnosityObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/canvas_qti_to_learnosity_converter/questions/multiple_choice.rb', line 38

def to_learnosity
  {
    stimulus: extract_stimulus(),
    options: extract_options(),
    multiple_responses: false,
    response_id: extract_response_id(),
    type: "mcq",
    validation: extract_validation(),
  }
end