Class: Qti::V1::Models::Interactions::BaseFillBlankInteraction

Inherits:
BaseInteraction show all
Defined in:
lib/qti/v1/models/interactions/base_fill_blank_interaction.rb

Instance Attribute Summary

Attributes inherited from BaseInteraction

#node

Attributes inherited from Models::Base

#doc, #manifest, #package_root, #path, #resource

Instance Method Summary collapse

Methods inherited from BaseInteraction

#answer_feedback, #canvas_item_feedback, canvas_multiple_fib?, #initialize, matches, maybe_question_type, question_type, #rcardinality, #scoring_data_structs, #shuffled?

Methods inherited from Base

#qti_version, #return_inner_content!

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

Instance Method Details

#canvas_blank_id(stem_item) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 37

def canvas_blank_id(stem_item)
  blank_id = nil
  node.xpath('.//xmlns:response_lid/xmlns:material').children.map do |response_lid_node|
    if stem_item == response_lid_node.text
      blank_id = response_lid_node.ancestors('response_lid').first.attributes['ident']&.value
    end
  end
  blank_id
end

#canvas_fib_response_idsObject



61
62
63
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 61

def canvas_fib_response_ids
  @canvas_fib_response_ids ||= canvas_fib_responses.map { |b| "[#{b[:id].sub(/^response_/, '')}]" }
end

#canvas_fib_responsesObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 47

def canvas_fib_responses
  @base_canvas_blanks ||= node.xpath('.//xmlns:response_lid').map do |resp|
    index = 0
    {
      id: resp[:ident],
      choices:
        resp.xpath('.//xmlns:response_label').map do |bnode|
          canvas_blank_choice(bnode, index += 1)
        end
    }
  end
  @base_canvas_blanks
end

#canvas_stem_items(item_prompt) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 8

def canvas_stem_items(item_prompt)
  item_prompt.split(CANVAS_REGEX).map.with_index do |stem_item, index|
    if canvas_fib_response_ids.include?(stem_item)
      # Strip the brackets before searching
      stem_blank(index, canvas_blank_id(stem_item[1..-2]))
    else
      stem_text(index, stem_item)
    end
  end
end

#stem_blank(index, value) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 19

def stem_blank(index, value)
  {
    id: "stem_#{index}",
    position: index + 1,
    type: 'blank',
    blank_id: value
  }
end

#stem_text(index, value) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 28

def stem_text(index, value)
  {
    id: "stem_#{index}",
    position: index + 1,
    type: 'text',
    value: value
  }
end