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

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

Constant Summary

Constants inherited from Models::Base

Models::Base::ELEMENTS_REMAP

Instance Attribute Summary

Attributes inherited from BaseInteraction

#node

Attributes inherited from Models::Base

#doc, #manifest, #package_root, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseInteraction

#answer_feedback, #canvas_item_feedback, canvas_multiple_fib?, #initialize, #rcardinality, #shuffled?

Methods inherited from Base

#qti_version, #return_inner_content!

Methods inherited from Models::Base

#css_with_single_check, from_path!, #initialize, #object_tag_transformer, #parse_html, #parse_xml, #preprocess_xml_doc, #remap_href_path, #remap_unknown_tags_transformer, #sanitize_config, #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



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

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

#formula_decimal_placesObject



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

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

#formulasObject



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

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

#margin_of_errorObject



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

def margin_of_error
  if answer_tolerance.ends_with? '%'
    return { margin: answer_tolerance[0..-2], margin_type: 'percent' }
  end
  { 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
38
39
40
41
42
# 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|
    {
      name: vnode.attributes['name']&.value,
      min: vnode.at_xpath('.//xmlns:min').text,
      max: vnode.at_xpath('.//xmlns:max').text,
      precision: vnode.attributes['scale']&.value
    }
  end
end