Class: Qti::V1::Models::Interactions::CanvasMultipleDropdownInteraction

Inherits:
BaseFillBlankInteraction show all
Defined in:
lib/qti/v1/models/interactions/canvas_multiple_dropdown.rb

Instance Attribute Summary

Attributes inherited from BaseInteraction

#node

Attributes inherited from Models::Base

#doc, #manifest, #package_root, #path, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseFillBlankInteraction

#blank_id, #blank_value, #canvas_blank_id, #canvas_custom_fitb?, #canvas_fib_response_ids, #canvas_fib_responses, #canvas_stem_items, #correct_answer_map, #new_quizzes_fib?, #nq_blank_id, #nq_blank_value, #stem_blank, #stem_text

Methods inherited from BaseInteraction

#answer_feedback, canvas_custom_fitb?, #canvas_item_feedback, canvas_multiple_fib?, #initialize, #locked_choices, maybe_question_type, new_quizzes_fib?, question_type, #rcardinality, #shuffled?

Methods inherited from Base

#qti_version, #return_inner_content!, #sanitize_attributes, #sanitize_attributes_by_node

Methods inherited from Models::Base

#css_with_single_check, from_path!, #initialize, #parse_html, #parse_xml, #preprocess_xml_doc, #raise_unsupported, #remap_href_path, #sanitize_content!, #xpath_with_single_check

Constructor Details

This class inherits a constructor from Qti::V1::Models::Interactions::BaseInteraction

Class Method Details

.matches(node, parent) ⇒ Object

This will know if a class matches



7
8
9
10
11
# File 'lib/qti/v1/models/interactions/canvas_multiple_dropdown.rb', line 7

def self.matches(node, parent)
  field_entry = node.xpath('.//xmlns:fieldentry')[0]
  return false unless field_entry&.text == 'multiple_dropdowns_question'
  new(node, parent)
end

Instance Method Details

#answersObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/qti/v1/models/interactions/canvas_multiple_dropdown.rb', line 41

def answers
  @node.xpath('.//xmlns:respcondition/xmlns:setvar[@varname="SCORE"]').map do |points|
    entry = points.at_xpath('preceding-sibling::xmlns:conditionvar/xmlns:varequal')
    {
      value: entry[:respident],
      entry_id: entry.text,
      blank_text: text_for_entry(entry.text),
      action: points[:action],
      point_value: points.text
    }
  end
end

#position_for_entry(entry_id) ⇒ Object



36
37
38
39
# File 'lib/qti/v1/models/interactions/canvas_multiple_dropdown.rb', line 36

def position_for_entry(entry_id)
  canvas_fib_responses
  @blank_choices[entry_id][:position]
end

#scoring_data_structsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/qti/v1/models/interactions/canvas_multiple_dropdown.rb', line 17

def scoring_data_structs
  answers.map do |answer|
    ScoringData.new(
      {
        id: answer[:entry_id],
        position: position_for_entry(answer[:entry_id]),
        item_body: answer[:blank_text]
      },
      rcardinality,
      id: answer[:value]
    )
  end
end

#stem_itemsObject



13
14
15
# File 'lib/qti/v1/models/interactions/canvas_multiple_dropdown.rb', line 13

def stem_items
  canvas_stem_items(node.at_xpath('.//xmlns:presentation/xmlns:material/xmlns:mattext').text)
end

#text_for_entry(entry_id) ⇒ Object



31
32
33
34
# File 'lib/qti/v1/models/interactions/canvas_multiple_dropdown.rb', line 31

def text_for_entry(entry_id)
  canvas_fib_responses
  @blank_choices[entry_id][:item_body]
end