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_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



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, item_body: item_body }
  end
end

#scoring_algorithmObject



38
39
40
41
42
43
# File 'lib/qti/v1/models/interactions/match_interaction.rb', line 38

def scoring_algorithm
  scoring_algorithm_path = './/xmlns:qtimetadatafield/xmlns:fieldlabel' \
  '[text()="scoring_algorithm"]/../xmlns:fieldentry'

  node.at_xpath(scoring_algorithm_path)&.text
end

#scoring_data_structsObject



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

def scoring_data_structs
  @scoring_data_structs ||= parse_scoring_data
end