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_item_feedback, canvas_multiple_fib?, #initialize, maybe_question_type, question_type, #rcardinality, #shuffled?

Methods inherited from Base

#qti_version, #return_inner_content!

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



39
40
41
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 39

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

#formula_decimal_placesObject



48
49
50
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 48

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

#formulasObject



52
53
54
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 52

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

#margin_of_errorObject



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

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
# File 'lib/qti/v1/models/interactions/formula_interaction.rb', line 23

def solutions
  node.xpath('.//xmlns:var_set').map do |anode|
    {
      inputs: vars_at_node(anode),
      output: anode.at_xpath('.//xmlns:answer')&.text&.to_f
    }
  end
end

#variablesObject



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

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