Class: Qti::V1::Models::Interactions::BaseFillBlankInteraction
Instance Attribute Summary
#node
Attributes inherited from Models::Base
#doc, #manifest, #package_root, #path, #resource
Instance Method Summary
collapse
#answer_feedback, canvas_custom_fitb?, #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!, #sanitize_attributes, #sanitize_attributes_by_node
#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
Instance Method Details
#blank_id(stem_item) ⇒ Object
40
41
42
43
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 40
def blank_id(stem_item)
return stem_item unless canvas_custom_fitb?
canvas_blank_id(stem_item)
end
|
#blank_value(blank_id) ⇒ Object
45
46
47
48
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 45
def blank_value(blank_id)
blank = canvas_fib_responses.find { |response| response[:id] == blank_id }
blank&.dig(:choices, 0, :item_body)
end
|
#canvas_blank_id(stem_item) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 54
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_custom_fitb? ⇒ Boolean
50
51
52
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 50
def canvas_custom_fitb?
@canvas_custom_fitb ||= BaseInteraction.canvas_custom_fitb?(@node)
end
|
#canvas_fib_response_ids ⇒ Object
78
79
80
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 78
def canvas_fib_response_ids
@canvas_fib_response_ids ||= canvas_fib_responses.map { |b| "[#{b[:id].sub(/^response_/, '')}]" }
end
|
#canvas_fib_responses ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 64
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
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 6
def canvas_stem_items(item_prompt)
item_prompt = sanitize_attributes(item_prompt)
item_prompt.split(CANVAS_BLANK_REGEX).map.with_index do |stem_item, index|
if canvas_fib_response_ids.include?(stem_item)
value = stem_item[1..-2]
blank_id = blank_id(value)
blank_name = blank_value(blank_id) || value
stem_blank(index, blank_id, blank_name)
else
stem_text(index, stem_item)
end
end
end
|
#stem_blank(index, blank_id, blank_name) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 21
def stem_blank(index, blank_id, blank_name)
{
id: "stem_#{index}",
position: index + 1,
type: 'blank',
blank_id: blank_id,
blank_name: blank_name
}
end
|
#stem_text(index, value) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 31
def stem_text(index, value)
{
id: "stem_#{index}",
position: index + 1,
type: 'text',
value: value
}
end
|