module Qti::V1::Models::Interactions
Constants
- ALL_CLASSES
- FALLBACK_CLASSES
- IDENTIFIED_CLASSES
- ORDERED_CLASSES
Public Class Methods
get_match(node, parent, classlist)
click to toggle source
# File lib/qti/v1/models/interactions.rb, line 52 def self.get_match(node, parent, classlist) classlist.each do |interaction_class| return true if interaction_class.match(node, parent) end end
get_matches(node, parent, classlist)
click to toggle source
# File lib/qti/v1/models/interactions.rb, line 58 def self.get_matches(node, parent, classlist) matches = classlist.each_with_object([]) do |interaction_class, result| match = interaction_class.matches(node, parent) result << match if match end matches end
interaction_model(node, parent)
click to toggle source
This one finds the correct parsing model based on the provided xml node
# File lib/qti/v1/models/interactions.rb, line 25 def self.interaction_model(node, parent) matched_class(node, parent) || searched_class(node, parent) end
matched_class(node, parent)
click to toggle source
# File lib/qti/v1/models/interactions.rb, line 42 def self.matched_class(node, parent) IDENTIFIED_CLASSES[question_type(node)]&.new(node, parent) end
question_type(node)
click to toggle source
# File lib/qti/v1/models/interactions.rb, line 46 def self.question_type(node) path = './/xmlns:qtimetadatafield/xmlns:fieldlabel' \ '[text()="question_type"]/../xmlns:fieldentry' node.at_xpath(path)&.text end
searched_class(node, parent)
click to toggle source
# File lib/qti/v1/models/interactions.rb, line 29 def self.searched_class(node, parent) matches = Interactions.get_matches(node, parent, ORDERED_CLASSES) return matches.first unless matches.empty? subclasses = ALL_CLASSES - ORDERED_CLASSES - FALLBACK_CLASSES matches = Interactions.get_matches(node, parent, subclasses) matches = Interactions.get_matches(node, parent, FALLBACK_CLASSES) if matches.empty? raise UnsupportedSchema, "Multiple Types (#{matches.map(&:class)})" if matches.size != 1 matches.first end