Class: Qti::V1::Models::Interactions::BaseInteraction

Inherits:
Base show all
Defined in:
lib/qti/v1/models/interactions/base_interaction.rb

Instance Attribute Summary collapse

Attributes inherited from Models::Base

#doc, #manifest, #package_root, #path, #resource

Class Method Summary collapse

Instance Method Summary collapse

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!, #parse_html, #parse_xml, #preprocess_xml_doc, #raise_unsupported, #remap_href_path, #sanitize_content!, #xpath_with_single_check

Constructor Details

#initialize(node, parent) ⇒ BaseInteraction

Returns a new instance of BaseInteraction.



43
44
45
46
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 43

def initialize(node, parent)
  @node = node
  copy_paths_from_item(parent)
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



6
7
8
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 6

def node
  @node
end

Class Method Details

.canvas_custom_fitb?(node) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 12

def self.canvas_custom_fitb?(node)
  qtype = question_type(node)
  %w[fill_in_multiple_blanks_question multiple_dropdowns_question].include? qtype
end

.canvas_multiple_fib?(node) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.matches(_node, _parent) ⇒ Object



8
9
10
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 8

def self.matches(_node, _parent)
  false
end

.maybe_question_type(node, qtype) ⇒ Object



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

def self.maybe_question_type(node, qtype)
  question_type = self.question_type(node)
  !question_type || question_type == qtype
end

.new_quizzes_fib?(node) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 23

def self.new_quizzes_fib?(node)
  return false unless canvas_multiple_fib?(node)

  first_match = node.at_xpath('.//xmlns:response_label')
  return false if first_match.blank?

  first_match.attr('scoring_algorithm').present?
end

.question_type(node) ⇒ Object



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

def self.question_type(node)
  path = './/xmlns:qtimetadatafield/xmlns:fieldlabel' \
    '[text()="question_type"]/../xmlns:fieldentry'
  node.at_xpath(path)&.text
end

Instance Method Details

#answer_feedbackObject



78
79
80
81
82
83
84
85
86
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 78

def answer_feedback
  path = './/xmlns:respcondition//xmlns:displayfeedback/../' \
    'xmlns:conditionvar/xmlns:varequal[@respident]/../../' \
    'xmlns:displayfeedback/..'
  answers = node.xpath(path).map do |entry|
    answer_feedback_entry(entry)
  end.compact
  answers unless answers.empty?
end

#canvas_item_feedbackObject



70
71
72
73
74
75
76
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 70

def canvas_item_feedback
  {
    neutral: get_feedback('general_fb')&.text,
    correct: get_feedback('correct_fb')&.text,
    incorrect: get_feedback('general_incorrect_fb')&.text
  }.compact
end

#locked_choicesObject



52
53
54
55
56
57
58
59
60
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 52

def locked_choices
  return [] unless shuffled?

  @node.xpath('.//xmlns:response_label').filter_map.with_index do |answer_node, index|
    is_locked = answer_node.attributes['lock']&.value&.downcase == 'yes'

    is_locked ? index : nil
  end
end

#rcardinalityObject



66
67
68
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 66

def rcardinality
  @rcardinality ||= @node.at_xpath('.//xmlns:response_lid/@rcardinality')&.value || 'Single'
end

#scoring_data_structsObject

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 62

def scoring_data_structs
  raise NotImplementedError
end

#shuffled?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/qti/v1/models/interactions/base_interaction.rb', line 48

def shuffled?
  @node.at_xpath('.//xmlns:render_choice/@shuffle')&.value.try(:downcase) == 'yes'
end