Class: Qti::V2::Models::Interactions::BaseInteraction

Inherits:
Base show all
Defined in:
lib/qti/v2/models/interactions/base_interaction.rb

Constant Summary

Constants inherited from Base

Base::BODY_ELEMENTS_CSS, Base::CHOICE_ELEMENTS_CSS, Base::INTERACTION_ELEMENTS_CSS

Constants inherited from Models::Base

Models::Base::ELEMENTS_REMAP

Instance Attribute Summary collapse

Attributes inherited from Models::Base

#doc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#qti_version

Methods inherited from Models::Base

#css_with_single_check, from_path!, #parse_xml, #remap_href_path, #remap_unknown_tags_transformer, #sanitize_config, #sanitize_content!

Constructor Details

#initialize(node) ⇒ BaseInteraction

Returns a new instance of BaseInteraction.



12
13
14
# File 'lib/qti/v2/models/interactions/base_interaction.rb', line 12

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



6
7
8
# File 'lib/qti/v2/models/interactions/base_interaction.rb', line 6

def node
  @node
end

Class Method Details

.matches(node) ⇒ Object



8
9
10
# File 'lib/qti/v2/models/interactions/base_interaction.rb', line 8

def self.matches(node)
  false
end

Instance Method Details

#scoring_data_structsObject



20
21
22
23
24
25
26
# File 'lib/qti/v2/models/interactions/base_interaction.rb', line 20

def scoring_data_structs
  @scoring_data_structs ||= begin
    type = xpath_with_single_check('//xmlns:responseDeclaration/@baseType').content
    value_nodes = node.xpath('//xmlns:responseDeclaration/xmlns:correctResponse/xmlns:value')
    value_nodes.map { |value_node| Models::ScoringData.new(value_node.content, type) }
  end
end

#shuffled?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/qti/v2/models/interactions/base_interaction.rb', line 16

def shuffled?
  @node.attributes['shuffle']&.value.try(:downcase) == 'true'
end

#xpath_with_single_check(xpath) ⇒ Object

Raises:



28
29
30
31
32
# File 'lib/qti/v2/models/interactions/base_interaction.rb', line 28

def xpath_with_single_check(xpath)
  node_list = node.xpath(xpath)
  raise Qti::ParseError, 'Too many matches' if node_list.count > 1
  node_list.first
end