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

Inherits:
BaseFillBlankInteraction show all
Defined in:
lib/qti/v1/models/interactions/fill_blank_interaction.rb

Instance Attribute Summary

Attributes inherited from BaseInteraction

#node

Attributes inherited from Models::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseFillBlankInteraction

#canvas_blank_id, #canvas_stem_items, #stem_blank, #stem_text

Methods inherited from BaseInteraction

#answer_feedback, #canvas_item_feedback, canvas_multiple_fib?, #initialize, maybe_question_type, question_type, #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

Class Method Details

.match_and_answers(node) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 16

def self.match_and_answers(node)
  if BaseInteraction.canvas_multiple_fib?(node)
    return [
      node.at_xpath('.//xmlns:response_lid'),
      node.xpath('.//xmlns:response_label')
    ]
  end
  [
    node.at_xpath('.//xmlns:render_fib'),
    node.xpath('.//xmlns:respcondition/xmlns:setvar/../xmlns:conditionvar/xmlns:varequal')
  ]
end

.matches(node, parent) ⇒ Object

This will know if a class matches



7
8
9
10
11
12
13
14
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 7

def self.matches(node, parent)
  return false if node.at_xpath('.//xmlns:respcondition[@continue!="Yes"]/*/xmlns:other').present?

  match, answers = FillBlankInteraction.match_and_answers(node)
  return false if answers.blank?
  return false if match.blank? || match.attributes['fibtype']&.value == 'Decimal'
  new(node, parent)
end

Instance Method Details

#answersObject



72
73
74
75
76
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 72

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

#blanksObject



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

def blanks
  if node.at_xpath('.//xmlns:render_choice').present?
    canvas_blanks
  else
    qti_standard_blanks
  end
end

#canvas_blanksObject



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

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

#canvas_multiple_fib?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 29

def canvas_multiple_fib?
  @canvas_multiple_fib ||= BaseInteraction.canvas_multiple_fib?(@node)
end

#qti_standard_blanksObject



66
67
68
69
70
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 66

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

#qti_stem_itemsObject



41
42
43
44
45
46
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 41

def qti_stem_items
  stem_item_nodes = node.xpath('.//xmlns:presentation').children
  stem_item_nodes.map.with_index do |stem_item, index|
    qti_stem_item(index, stem_item)
  end
end

#scoring_data_structsObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 78

def scoring_data_structs
  answer_nodes.map do |value_node|
    ScoringData.new(
      value_node.content,
      rcardinality,
      id: scoring_data_id(value_node),
      case: scoring_data_case(value_node),
      parent_identifier: value_node.parent.parent.attributes['ident']&.value
    )
  end
end

#single_fill_in_blank?Boolean

Returns:

  • (Boolean)


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

def single_fill_in_blank?
  !canvas_multiple_fib? && blanks.count == 1
end

#stem_itemsObject



33
34
35
36
37
38
39
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 33

def stem_items
  if canvas_multiple_fib?
    canvas_stem_items(node.at_xpath('.//xmlns:mattext').text)
  else
    qti_stem_items
  end
end