Class: Qti::V1::Models::Interactions::FillBlankInteraction

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v1/models/interactions/fill_blank_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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseInteraction

#shuffled?

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!, #xpath_with_single_check

Constructor Details

#initialize(node) ⇒ FillBlankInteraction

Returns a new instance of FillBlankInteraction.



14
15
16
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 14

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
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 7

def self.matches(node)
  return false if node.xpath('.//xmlns:other').present?
  matches = node.xpath('.//xmlns:render_fib')
  return false if matches.empty?
  new(node)
end

Instance Method Details

#answersObject



45
46
47
48
49
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 45

def answers
  @answers ||= answer_nodes.map do |node|
    V1::Models::Choices::FillBlankChoice.new(node)
  end
end

#blanksObject



39
40
41
42
43
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 39

def blanks
  node.xpath('.//xmlns:response_str').map do |blank|
    { id: blank.attributes['ident'].value }
  end
end

#scoring_data_structsObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 51

def scoring_data_structs
  answer_nodes.map { |value_node| ScoringData.new(
      value_node.content,
      rcardinality,
      {
        id: value_node.attributes['respident']&.value,
        case: value_node.attributes['case']&.value
      }
    )
  }
end

#stem_itemsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 18

def stem_items
  stem_item_nodes = node.xpath('.//xmlns:presentation').children
  stem_item_nodes.map.with_index do |stem_item, index|
    if stem_item.xpath('./xmlns:render_fib').present?
      {
        id: "stem_#{index}",
        position: index + 1,
        type: 'blank',
        blank_id: stem_item.attributes['ident'].value
      }
    else
      {
        id: "stem_#{index}",
        position: index + 1,
        type: 'text',
        value: stem_item.children.text
      }
    end
  end
end