Class: Qti::V1::Models::Interactions::NumericInteraction

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v1/models/interactions/numeric_interaction.rb

Instance Attribute Summary

Attributes inherited from BaseInteraction

#node

Attributes inherited from Models::Base

#doc, #manifest, #package_root, #path, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseInteraction

canvas_custom_fitb?, #canvas_item_feedback, canvas_multiple_fib?, #initialize, #locked_choices, maybe_question_type, new_quizzes_fib?, question_type, #rcardinality, #shuffled?

Methods inherited from Base

#qti_version, #return_inner_content!, #sanitize_attributes, #sanitize_attributes_by_node

Methods inherited from Models::Base

#css_with_single_check, from_path!, #initialize, #parse_html, #parse_xml, #preprocess_xml_doc, #raise_unsupported, #remap_href_path, #sanitize_content!, #xpath_with_single_check

Constructor Details

This class inherits a constructor from Qti::V1::Models::Interactions::BaseInteraction

Class Method Details

.matches(node, parent) ⇒ Object

This will know if a class matches



7
8
9
10
11
12
# File 'lib/qti/v1/models/interactions/numeric_interaction.rb', line 7

def self.matches(node, parent)
  first_match = node.at_xpath('.//xmlns:render_fib')
  return false unless first_match && first_match.attributes['fibtype']&.value == 'Decimal'
  return false if node.xpath('.//xmlns:render_fib').count > 1
  new(node, parent)
end

Instance Method Details

#answer_feedback ⇒ Object

Numeric answers cannot be paired with their comment through a varequal, the way the base implementation does it: exact and precision answers nest it inside an or, and range answers have no single value to emit one for. Canvas instead puts each answer's displayfeedback in the same respcondition that carries its setvar SCORE, so pair them by that node and key the result on the position within answer_nodes -- the same list, in the same order, that scoring_data_structs is built from.



40
41
42
43
44
45
# File 'lib/qti/v1/models/interactions/numeric_interaction.rb', line 40

def answer_feedback
  answers = answer_nodes.filter_map.with_index do |answer_node, index|
    numeric_answer_feedback_entry(answer_node, index)
  end
  answers unless answers.empty?
end

#item_body ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/qti/v1/models/interactions/numeric_interaction.rb', line 14

def item_body
  @item_body ||= begin
    node = @node.dup
    presentation = node.at_xpath('.//xmlns:presentation')
    mattext = presentation.at_xpath('.//xmlns:mattext')
    inner_content = return_inner_content!(mattext)
    sanitize_content!(inner_content)
  end
end

#scoring_data_structs ⇒ Object



24
25
26
27
28
29
30
# File 'lib/qti/v1/models/interactions/numeric_interaction.rb', line 24

def scoring_data_structs
  answer_nodes.map do |value_node|
    V1::Models::Numerics::ScoringData.new(
      value_node
    ).scoring_data
  end
end