Class: Qti::V2::Models::Interactions::ChoiceInteraction
- Inherits:
-
Base
- Object
- Models::Base
- Base
- Qti::V2::Models::Interactions::ChoiceInteraction
- Defined in:
- lib/qti/v2/models/interactions/choice_interaction.rb
Constant Summary collapse
- NODE_NAME =
'choiceInteraction'.freeze
Constants inherited from Base
Base::BODY_ELEMENTS_CSS, Base::CHOICE_ELEMENTS_CSS, Base::INTERACTION_ELEMENTS_CSS
Constants 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.
- #max_choices_count ⇒ Object
- #min_choices_count ⇒ Object
- #shuffled? ⇒ Boolean
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.
19 20 21 |
# File 'lib/qti/v2/models/interactions/choice_interaction.rb', line 19 def initialize(node) @node = node end |
Class Method Details
.matches(node) ⇒ Object
This will know if a class matches
11 12 13 14 15 16 17 |
# File 'lib/qti/v2/models/interactions/choice_interaction.rb', line 11 def self.matches(node) matches = node.children.filter(INTERACTION_ELEMENTS_CSS).select { |n| n.name == NODE_NAME } return false if matches.empty? raise Qti::UnsupportedSchema if matches.size > 1 new(matches.first) end |
Instance Method Details
#answers ⇒ Object
27 28 29 30 31 |
# File 'lib/qti/v2/models/interactions/choice_interaction.rb', line 27 def answers @answers ||= answer_nodes.map do |node| V2::Models::Choices::SimpleChoice.new(node) end end |
#max_choices_count ⇒ Object
33 34 35 |
# File 'lib/qti/v2/models/interactions/choice_interaction.rb', line 33 def max_choices_count @node.attributes['maxChoices']&.value&.to_i end |
#min_choices_count ⇒ Object
37 38 39 |
# File 'lib/qti/v2/models/interactions/choice_interaction.rb', line 37 def min_choices_count @node.attributes['minChoices']&.value&.to_i end |
#shuffled? ⇒ Boolean
23 24 25 |
# File 'lib/qti/v2/models/interactions/choice_interaction.rb', line 23 def shuffled? @node.attributes['shuffle'].value == 'true' end |