class Qti::V1::Models::Interactions::MatchInteraction
Public Class Methods
matches(node, parent)
click to toggle source
# 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
Public Instance Methods
answers()
click to toggle source
# 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
distractors()
click to toggle source
# 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
questions()
click to toggle source
# 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, itemBody: item_body } end end
scoring_data_structs()
click to toggle source
# File lib/qti/v1/models/interactions/match_interaction.rb, line 28 def scoring_data_structs @scoring_data_structs ||= parse_scoring_data end
Private Instance Methods
answer_nodes()
click to toggle source
# File lib/qti/v1/models/interactions/match_interaction.rb, line 55 def answer_nodes responses = [] response_ids = {} node.xpath('.//xmlns:response_label').each do |answer_node| ident = answer_node.attributes['ident'].value responses << answer_node unless response_ids.key? ident response_ids[ident] = 1 end responses end
answers_map()
click to toggle source
# File lib/qti/v1/models/interactions/match_interaction.rb, line 49 def answers_map @answers_map ||= answers.reduce({}) do |acc, answer| acc.update answer.identifier => answer.item_body end end
parse_scoring_data()
click to toggle source
# File lib/qti/v1/models/interactions/match_interaction.rb, line 40 def parse_scoring_data # This preserves the original behavior while not breaking on item feedback path = './/xmlns:respcondition/xmlns:setvar/../xmlns:conditionvar/xmlns:varequal' matches = node.xpath(path).map do |node| [node.attributes['respident'].value, answers_map[node.content]] end [Models::ScoringData.new(Hash[matches], rcardinality)] end