Class: Qti::V2::Models::Interactions::MatchItemTagProcessors::MatchInteractionTagProcessor

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb

Constant Summary

Constants inherited from Base

Base::BODY_ELEMENTS_CSS, Base::CHOICE_ELEMENTS_CSS, Base::INTERACTION_ELEMENTS_CSS

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 BaseInteraction

#canvas_item_feedback, #initialize, matches, #xpath_with_single_check

Methods inherited from Base

#qti_version

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::V2::Models::Interactions::BaseInteraction

Class Method Details

.match_interaction_tag?(node) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 7

def self.match_interaction_tag?(node)
  node.xpath('//xmlns:matchInteraction').count == 1
end

.number_of_questions_per_answer(node) ⇒ Object



11
12
13
14
15
16
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 11

def self.number_of_questions_per_answer(node)
  correct_categories = node.xpath('.//xmlns:correctResponse//xmlns:value')
                           .map { |value| value.content.split.last }

  correct_categories.each_with_object(Hash.new(0)) { |category_id, counts| counts[category_id] += 1 }.values
end

Instance Method Details

#answersObject



26
27
28
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 26

def answers
  answer_nodes.map { |node| Choices::SimpleAssociableChoice.new(node, self) }
end

#choicesObject



37
38
39
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 37

def choices
  node.xpath('.//xmlns:simpleAssociableChoice')
end

#question_response_pairsObject



41
42
43
44
45
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 41

def question_response_pairs
  node.xpath('.//xmlns:correctResponse//xmlns:value').map do |value|
    value.content.split
  end
end

#questionsObject



18
19
20
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 18

def questions
  questions_ids.map { |id| { id: id, itemBody: choices_by_identifier[id].content } }
end

#scoring_data_structsObject



30
31
32
33
34
35
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 30

def scoring_data_structs
  question_response_pairs.map do |question_id, answer_id|
    content = choices_by_identifier[answer_id].content
    ScoringData.new(content, 'Pair', id: answer_id, question_id: question_id)
  end
end

#shuffled?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/match_interaction_tag_processor.rb', line 22

def shuffled?
  node.at_xpath('.//xmlns:matchInteraction').attributes['shuffle']&.value.try(:downcase) == 'true'
end