class Qti::V2::Models::Interactions::MatchItemTagProcessors::AssociateInteractionTagProcessor

Public Class Methods

associate_interaction_tag?(node) click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 7
def self.associate_interaction_tag?(node)
  node.xpath('.//xmlns:associateInteraction').count == 1
end
number_of_questions_per_answer(node) click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 11
def self.number_of_questions_per_answer(node)
  question_response_pairs = node.xpath('.//xmlns:correctResponse//xmlns:value').map do |value|
    value.content.split
  end
  count = Hash.new { 0 }
  question_response_pairs.reduce(count) do |acc, pair|
    acc.update pair.last => acc[pair.last] + 1
  end
  count.values
end

Public Instance Methods

answers() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 30
def answers
  answer_nodes.map { |node| Choices::SimpleAssociableChoice.new(node, self) }
end
questions() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 26
def questions
  questions_ids.map { |id| { id: id, itemBody: choices_by_identifier[id].content } }
end
scoring_data_structs() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 34
def scoring_data_structs
  question_response_pairs.map do |question_id, answer_id|
    content = choices_by_identifier[answer_id].content
    ScoringData.new(content, 'Pair', id: answer_id, question_id: question_id)
  end
end
shuffled?() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 22
def shuffled?
  node.at_xpath('.//xmlns:associateInteraction').attributes['shuffle']&.value.try(:downcase) == 'true'
end

Private Instance Methods

answer_ids() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 57
def answer_ids
  @_answer_ids ||= question_response_pairs.map { |_, answer_id| answer_id }
end
answer_nodes() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 49
def answer_nodes
  @_answer_nodes ||= choices.select { |c| answer_ids.include?(c.attributes['identifier'].value) }
end
choices() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 61
def choices
  node.xpath('.//xmlns:simpleAssociableChoice')
end
choices_by_identifier() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 43
def choices_by_identifier
  @_choices_by_identifier ||= choices.reduce({}) do |acc, choice|
    acc.update choice.attributes['identifier'].value => choice
  end
end
question_response_pairs() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 65
def question_response_pairs
  node.xpath('.//xmlns:correctResponse//xmlns:value').map do |value|
    value.content.split
  end
end
questions_ids() click to toggle source
# File lib/qti/v2/models/interactions/match_item_tag_processors/associate_interaction_tag_processor.rb, line 53
def questions_ids
  @_questions_ids ||= question_response_pairs.map { |question_id, _| question_id }
end