Class: Qti::V1::Models::Interactions::MatchInteraction

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v1/models/interactions/match_interaction.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 BaseInteraction

#answer_feedback, #canvas_item_feedback, canvas_multiple_fib?, #initialize, maybe_question_type, question_type, #rcardinality, #shuffled?

Methods inherited from Base

#qti_version, #return_inner_content!

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



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

def self.matches(node, parent)
  return false if canvas_multiple_fib?(node)
  matches = node.xpath('.//xmlns:response_lid')
  return false if matches.count <= 1
  new(node, parent)
end

Instance Method Details

#answersObject



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

def answers
  @answers ||= answer_nodes.map do |node|
    V1::Models::Choices::LogicalIdentifierChoice.new(node, self)
  end
end

#distractorsObject



32
33
34
35
36
# File 'lib/qti/v1/models/interactions/match_interaction.rb', line 32

def distractors
  correct = scoring_data_structs[0].values.map(&:second)
  all = answers.map(&:item_body)
  all.reject { |v| correct.include? v }
end

#questionsObject



19
20
21
22
23
24
25
26
# File 'lib/qti/v1/models/interactions/match_interaction.rb', line 19

def questions
  node.xpath('.//xmlns:response_lid').map do |lid_node|
    mattext = lid_node.at_xpath('.//xmlns:mattext')
    inner_content = return_inner_content!(mattext)
    item_body = sanitize_content!(inner_content)
    { id: lid_node.attributes['ident'].value, itemBody: item_body }
  end
end

#scoring_data_structsObject



28
29
30
# File 'lib/qti/v1/models/interactions/match_interaction.rb', line 28

def scoring_data_structs
  @scoring_data ||= parse_scoring_data
end