Class: Qti::V1::Models::Interactions::ChoiceInteraction
- Inherits:
-
BaseInteraction
- Object
- Models::Base
- Base
- BaseInteraction
- Qti::V1::Models::Interactions::ChoiceInteraction
- Defined in:
- lib/qti/v1/models/interactions/choice_interaction.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Models::Base
Instance Attribute Summary
Attributes inherited from BaseInteraction
Attributes inherited from Models::Base
Class Method Summary collapse
-
.matches(node) ⇒ Object
This will know if a class matches.
Instance Method Summary collapse
- #answers ⇒ Object
-
#initialize(node) ⇒ ChoiceInteraction
constructor
A new instance of ChoiceInteraction.
- #scoring_data_structs ⇒ Object
Methods inherited from BaseInteraction
Methods inherited from Base
Methods inherited from Models::Base
#css_with_single_check, from_path!, #parse_xml, #remap_href_path, #remap_unknown_tags_transformer, #sanitize_config, #sanitize_content!, #xpath_with_single_check
Constructor Details
#initialize(node) ⇒ ChoiceInteraction
Returns a new instance of ChoiceInteraction.
15 16 17 |
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 15 def initialize(node) @node = node end |
Class Method Details
.matches(node) ⇒ Object
This will know if a class matches
7 8 9 10 11 12 13 |
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 7 def self.matches(node) matches = node.xpath('.//xmlns:response_lid') return false if matches.count > 1 || matches.empty? rcardinality = matches.first.attributes['rcardinality']&.value || 'Single' return false if rcardinality == 'Ordered' new(node) end |
Instance Method Details
#answers ⇒ Object
19 20 21 22 23 |
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 19 def answers @answers ||= answer_nodes.map do |node| V1::Models::Choices::LogicalIdentifierChoice.new(node) end end |
#scoring_data_structs ⇒ Object
25 26 27 28 29 |
# File 'lib/qti/v1/models/interactions/choice_interaction.rb', line 25 def scoring_data_structs choice_nodes = node.xpath('.//xmlns:respcondition') set_var_nodes = choice_nodes.select { |choice_node| choice_node.at_xpath('.//xmlns:setvar').content.to_f.positive? } set_var_nodes.map { |value_node| ScoringData.new(value_node.at_xpath('.//xmlns:varequal').content, rcardinality) } end |