Class: Qti::V1::Models::Interactions::ChoiceInteraction

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v1/models/interactions/choice_interaction.rb

Direct Known Subclasses

OrderingInteraction

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

This will know if a class matches



7
8
9
10
11
12
13
14
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 7

def self.matches(node, parent)
  return false unless maybe_choice_type(node)
  matches = node.xpath('.//xmlns:response_lid')
  return false if matches.count > 1 || matches.empty?
  rcardinality = matches.first.attributes['rcardinality']&.value || 'Single'
  return false if rcardinality == 'Ordered'
  new(node, parent)
end

.maybe_choice_type(node) ⇒ Object



16
17
18
19
20
21
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 16

def self.maybe_choice_type(node)
  question_type = self.question_type(node)
  return true unless question_type
  valid_types = %w[multiple_choice_question multiple_answers_question true_false_question]
  valid_types.include?(question_type)
end

Instance Method Details

#answersObject



23
24
25
26
27
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 23

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

#meta_typeObject



29
30
31
32
33
34
35
36
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 29

def meta_type
  meta_node = node.at_xpath(
    './/xmlns:qtimetadatafield[./xmlns:fieldlabel/text()="question_type"]'
  )
  return nil unless meta_node.present?
  type_node = meta_node.at_xpath('.//xmlns:fieldentry')
  type_node&.text()
end

#scoring_algorithmObject



47
48
49
50
51
52
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 47

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



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

def scoring_data_structs
  choice_nodes = node.xpath('.//xmlns:respcondition')
  if choice_nodes.at_xpath('.//xmlns:and').present?
    scoring_data_condition(choice_nodes)
  else
    scoring_data(choice_nodes)
  end
end