class Qti::V1::Models::Interactions::BaseInteraction

Attributes

node[R]

Public Class Methods

canvas_multiple_fib?(node) click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 12
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) click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 8
def self.matches(_node, _parent)
  false
end
maybe_question_type(node, qtype) click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 24
def self.maybe_question_type(node, qtype)
  question_type = self.question_type(node)
  !question_type || question_type == qtype
end
new(node, parent) click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 29
def initialize(node, parent)
  @node = node
  copy_paths_from_item(parent)
end
question_type(node) click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 18
def self.question_type(node)
  path = './/xmlns:qtimetadatafield/xmlns:fieldlabel' \
    '[text()="question_type"]/../xmlns:fieldentry'
  node.at_xpath(path)&.text
end

Public Instance Methods

answer_feedback() click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 54
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
  answers unless answers.empty?
end
canvas_item_feedback() click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 46
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
rcardinality() click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 42
def rcardinality
  @rcardinality ||= @node.at_xpath('.//xmlns:response_lid/@rcardinality')&.value || 'Single'
end
scoring_data_structs() click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 38
def scoring_data_structs
  raise NotImplementedError
end
shuffled?() click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 34
def shuffled?
  @node.at_xpath('.//xmlns:render_choice/@shuffle')&.value.try(:downcase) == 'yes'
end

Private Instance Methods

answer_feedback_entry(entry) click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 66
def answer_feedback_entry(entry)
  ve = entry.xpath('.//xmlns:varequal').first
  refid = entry.xpath('./xmlns:displayfeedback').first[:linkrefid]
  feedback = get_feedback(refid)
  {
    response_id: ve[:respident],
    response_value: ve.text,
    texttype: feedback[:texttype],
    feedback: feedback.text
  }
end
get_feedback(ident) click to toggle source
# File lib/qti/v1/models/interactions/base_interaction.rb, line 78
def get_feedback(ident)
  node.xpath(".//xmlns:itemfeedback[@ident='#{ident}']/xmlns:*/xmlns:*/xmlns:mattext").first
end