Class: Qti::V1::Models::Interactions::FormulaInteraction

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v1/models/interactions/formula_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

#answer_feedback, 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



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

def self.matches(node, parent)
  return false unless node.at_xpath('.//xmlns:calculated').present?
  new(node, parent)
end

Instance Method Details

#answer_toleranceObject



41
42
43
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 41

def answer_tolerance
  @answer_tolerance ||= @node.at_xpath('.//xmlns:answer_tolerance').text
end

#formula_decimal_placesObject



50
51
52
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 50

def formula_decimal_places
  @node.at_xpath('.//xmlns:formulas/@decimal_places')&.value
end

#formula_scientific_notationObject



54
55
56
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 54

def formula_scientific_notation
  @node.at_xpath('.//xmlns:formulas/@scientific_notation')&.value == 'true'
end

#formulasObject



58
59
60
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 58

def formulas
  node.xpath('.//xmlns:formula').map(&:text)
end

#margin_of_errorObject



45
46
47
48
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 45

def margin_of_error
  return { margin: answer_tolerance[0..-2], margin_type: 'percent' } if answer_tolerance.ends_with? '%'
  { margin: answer_tolerance, margin_type: 'absolute' }
end

#scoring_data_structsObject



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

def scoring_data_structs
  solutions.map do |answer|
    ScoringData.new(
      answer[:output],
      rcardinality,
      id: answer[:id]
    )
  end
end

#solutionsObject



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

def solutions
  node.xpath('.//xmlns:var_set').map do |anode|
    output = anode.at_xpath('.//xmlns:answer')&.text

    {
      inputs: vars_at_node(anode),
      output: formula_scientific_notation ? output : output&.to_f
    }
  end
end

#variablesObject



34
35
36
37
38
39
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 34

def variables
  varlist = @node.at_xpath('.//xmlns:vars')
  varlist.xpath('.//xmlns:var').map do |vnode|
    variable_def(vnode)
  end
end