class Qti::V1::Models::Interactions::FillBlankInteraction

Public Class Methods

match_and_answers(node) click to toggle source
# 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) click to toggle source

This will know if a class matches

# 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

Public Instance Methods

answers() click to toggle source
# 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
blanks() click to toggle source
# 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_blanks() click to toggle source
# 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?() click to toggle source
# 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_blanks() click to toggle source
# 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_items() click to toggle source
# 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_structs() click to toggle source
# 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?() click to toggle source
# 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_items() click to toggle source
# 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

Private Instance Methods

answer_nodes() click to toggle source
# File lib/qti/v1/models/interactions/fill_blank_interaction.rb, line 97
def answer_nodes
  if canvas_multiple_fib?
    node.xpath('.//xmlns:response_label')
  else
    node.xpath('.//xmlns:respcondition/xmlns:setvar/../xmlns:conditionvar/xmlns:varequal')
  end
end
qti_stem_item(index, stem_item) click to toggle source
# File lib/qti/v1/models/interactions/fill_blank_interaction.rb, line 113
def qti_stem_item(index, stem_item)
  if stem_item.xpath('./xmlns:render_fib').present?
    stem_blank(index, stem_item.attributes['ident'].value)
  else
    stem_text(index, sanitize_content!(stem_item.children.text))
  end
end
rcardinality() click to toggle source
# File lib/qti/v1/models/interactions/fill_blank_interaction.rb, line 92
def rcardinality
  @rcardinality ||= @node.at_xpath('.//xmlns:response_str/@rcardinality')&.value ||
                    @node.at_xpath('.//xmlns:response_num/@rcardinality')&.value
end
scoring_data_case(node) click to toggle source
# File lib/qti/v1/models/interactions/fill_blank_interaction.rb, line 109
def scoring_data_case(node)
  node.attributes['case']&.value || 'no'
end
scoring_data_id(node) click to toggle source
# File lib/qti/v1/models/interactions/fill_blank_interaction.rb, line 105
def scoring_data_id(node)
  node.attributes['respident']&.value || node.attributes['ident']&.value
end