Class: Qti::V2::Models::Interactions::MatchItemTagProcessors::AssociateInteractionTagProcessor

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v2/models/interactions/match_item_tag_processors/associate_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

.associate_interaction_tag?(node) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.number_of_questions_per_answer(node) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb', line 11

def self.number_of_questions_per_answer(node)
  question_response_pairs = node.xpath('.//xmlns:correctResponse//xmlns:value').map do |value|
    value.content.split
  end
  count = Hash.new { 0 }
  question_response_pairs.reduce(count) do |acc, pair|
    acc.update pair.last => acc[pair.last] + 1
  end
  count.values
end

Instance Method Details

#answersObject



30
31
32
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb', line 30

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

#questionsObject



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

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

#scoring_data_structsObject



34
35
36
37
38
39
# File 'lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb', line 34

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/associate_interaction_tag_processor.rb', line 22

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