Class: Qti::V1::Models::Interactions::CategorizationInteraction
- Inherits:
-
BaseInteraction
- Object
- Models::Base
- Base
- BaseInteraction
- Qti::V1::Models::Interactions::CategorizationInteraction
- Defined in:
- lib/qti/v1/models/interactions/categorization_interaction.rb
Instance Attribute Summary
Attributes inherited from BaseInteraction
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_custom_fitb?, #canvas_item_feedback, canvas_multiple_fib?, #initialize, #locked_choices, maybe_question_type, new_quizzes_fib?, question_type, #rcardinality, #shuffled?
Methods inherited from Base
#qti_version, #return_inner_content!, #sanitize_attributes, #sanitize_attributes_by_node
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
6 7 8 9 10 11 12 13 |
# File 'lib/qti/v1/models/interactions/categorization_interaction.rb', line 6 def self.matches(node, parent) return false if canvas_multiple_fib?(node) matches = node.xpath('.//xmlns:response_lid') return false if matches.count <= 1 rcardinality = matches.first.attributes['rcardinality']&.value || 'Single' return false if rcardinality != 'Multiple' new(node, parent) end |
Instance Method Details
#categories ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/qti/v1/models/interactions/categorization_interaction.rb', line 25 def categories node.xpath('.//xmlns:response_lid').map do |lid_node| mattext = lid_node.at_xpath('.//xmlns:mattext') inner_content = return_inner_content!(mattext) item_body = sanitize_content!(inner_content) category_id = lid_node.attributes['ident'].value [category_id, { id: category_id, item_body: item_body }] end.to_h end |
#distractors ⇒ Object
35 36 37 38 39 |
# File 'lib/qti/v1/models/interactions/categorization_interaction.rb', line 35 def distractors @distractors ||= choices.reduce({}) do |acc, answer| acc.update answer.identifier => answer.item_body end end |
#item_body ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/qti/v1/models/interactions/categorization_interaction.rb', line 15 def item_body @item_body ||= begin node = @node.dup presentation = node.at_xpath('.//xmlns:presentation') mattext = presentation.at_xpath('.//xmlns:mattext') inner_content = return_inner_content!(mattext) sanitize_content!(inner_content) end end |
#scoring_data_structs ⇒ Object
41 42 43 |
# File 'lib/qti/v1/models/interactions/categorization_interaction.rb', line 41 def scoring_data_structs @scoring_data_structs ||= parse_scoring_data end |