Class: CanvasQtiToLearnosityConverter::MatchingQuestion

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

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



69
70
71
72
73
74
75
76
# File 'lib/canvas_qti_to_learnosity_converter/questions/matching.rb', line 69

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

#extract_response_identsObject



23
24
25
26
27
# File 'lib/canvas_qti_to_learnosity_converter/questions/matching.rb', line 23

def extract_response_idents()
  @xml.css("item > presentation > response_lid").map do |node|
    node.attribute("ident").text
  end
end

#extract_responsesObject



61
62
63
64
65
66
67
# File 'lib/canvas_qti_to_learnosity_converter/questions/matching.rb', line 61

def extract_responses()
  @xml.css("item > presentation > response_lid").map do |response|
    response.css("response_label mattext").map do |node|
      extract_mattext(node)
    end
  end
end

#extract_templateObject



17
18
19
20
21
# File 'lib/canvas_qti_to_learnosity_converter/questions/matching.rb', line 17

def extract_template()
  @xml.css("item > presentation > response_lid > material > mattext").map do |node|
    "<p>#{extract_mattext(node)} {{response}}</p>"
  end.join("\n")
end

#extract_valid_label_idents(valid_response_idents) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/canvas_qti_to_learnosity_converter/questions/matching.rb', line 29

def extract_valid_label_idents(valid_response_idents)
  valid_response_idents.map do |ident|
    @xml.css(%{item > resprocessing > respcondition varequal[respident="#{ident}"]}).map do |node|
      node.content
    end
  end.flatten
end

#extract_validationObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/canvas_qti_to_learnosity_converter/questions/matching.rb', line 37

def extract_validation()
  valid_response_idents = extract_response_idents()
  valid_label_idents = extract_valid_label_idents(valid_response_idents)

  valid_idents = Hash[valid_response_idents.zip(valid_label_idents)]

  valid_responses = valid_idents.map do |response_ident, label_ident|
    @xml.css(%{item > presentation >
      response_lid[ident="#{response_ident}"]
      response_label[ident="#{label_ident}"] > material > mattext}).map do |node|
      extract_mattext(node)
    end
  end.flatten

  {
    "scoring_type" => "partialMatchV2",
    "rounding" => "none",
    "valid_response" => {
      "value" => valid_responses,
      "score" => extract_points_possible,
    }
  }
end

#to_learnosityObject



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

def to_learnosity
  {
    type: "clozedropdown",
    stimulus: extract_stimulus(),
    template: extract_template(),
    validation: extract_validation(),
    possible_responses: extract_responses(),
    duplicate_responses: true,
    shuffle_options: true,
  }
end