class Qti::V1::Models::Interactions::ChoiceInteraction
Public Class Methods
matches(node, parent)
click to toggle source
This will know if a class matches
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 7 def self.matches(node, parent) return false unless maybe_choice_type(node) matches = node.xpath('.//xmlns:response_lid') return false if matches.count > 1 || matches.empty? rcardinality = matches.first.attributes['rcardinality']&.value || 'Single' return false if rcardinality == 'Ordered' new(node, parent) end
maybe_choice_type(node)
click to toggle source
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 16 def self.maybe_choice_type(node) question_type = self.question_type(node) return true unless question_type valid_types = %w[multiple_choice_question multiple_answers_question true_false_question] valid_types.include?(question_type) end
Public Instance Methods
answers()
click to toggle source
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 23 def answers @answers ||= answer_nodes.map do |node| V1::Models::Choices::LogicalIdentifierChoice.new(node, self) end end
meta_type()
click to toggle source
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 29 def meta_type meta_node = node.at_xpath( './/xmlns:qtimetadatafield[./xmlns:fieldlabel/text()="question_type"]' ) return nil unless meta_node.present? type_node = meta_node.at_xpath('.//xmlns:fieldentry') type_node&.text() end
scoring_data_structs()
click to toggle source
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 38 def scoring_data_structs choice_nodes = node.xpath('.//xmlns:respcondition') if choice_nodes.at_xpath('.//xmlns:and').present? scoring_data_condition(choice_nodes) else scoring_data(choice_nodes) end end
Private Instance Methods
answer_nodes()
click to toggle source
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 49 def answer_nodes node.xpath('.//xmlns:response_label') end
scoring_data(choice_nodes)
click to toggle source
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 61 def scoring_data(choice_nodes) set_var_nodes = choice_nodes.select do |choice_node| choice_node.at_xpath('.//xmlns:setvar')&.content&.to_f&.positive? end set_var_nodes.map do |value_node| ScoringData.new(value_node.at_xpath('.//xmlns:varequal').content, rcardinality) end end
scoring_data_condition(choice_nodes)
click to toggle source
# File lib/qti/v1/models/interactions/choice_interaction.rb, line 53 def scoring_data_condition(choice_nodes) answer_choices = choice_nodes.at_xpath('.//xmlns:and') answer_choices.children.filter('not').each(&:remove) answer_choices.children.map do |value_node| ScoringData.new(value_node.content, rcardinality) end end