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, #locked_choices, matches, maybe_question_type, new_quizzes_fib?, 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
44
|
# 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?
return canvas_blank_id(stem_item) unless new_quizzes_fib?
nq_blank_id(stem_item)
end
|
#blank_value(blank_id) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 46
def blank_value(blank_id)
return nq_blank_value(blank_id) if new_quizzes_fib?
blank = canvas_fib_responses.find { |response| response[:id] == blank_id }
correct_choice = blank[:choices].find { |c| c[:id] == correct_choice_id(blank) }
(correct_choice || {})[:item_body] || blank&.dig(:choices, 0, :item_body)
end
|
#canvas_blank_id(stem_item) ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 69
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
61
62
63
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 61
def canvas_custom_fitb?
@canvas_custom_fitb ||= BaseInteraction.canvas_custom_fitb?(@node)
end
|
#canvas_fib_response_ids ⇒ Object
101
102
103
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 101
def canvas_fib_response_ids
@canvas_fib_response_ids ||= canvas_fib_responses.map { |b| "[#{b[:id].sub(/^response_/, '')}]" }
end
|
#canvas_fib_responses ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 87
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
|
#correct_answer_map ⇒ Object
105
106
107
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 105
def correct_answer_map
@correct_answer_map ||= correct_answers
end
|
#new_quizzes_fib? ⇒ Boolean
65
66
67
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 65
def new_quizzes_fib?
@new_quizzes_fib ||= BaseInteraction.new_quizzes_fib?(@node)
end
|
#nq_blank_id(stem_item) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 79
def nq_blank_id(stem_item)
blank_id = nil
node.xpath('.//xmlns:response_lid').map do |resp|
blank_id = resp[:ident] if resp[:ident] == "response_#{stem_item}"
end
blank_id
end
|
#nq_blank_value(blank_id) ⇒ Object
The correct answer value is not necessarily the first one in NQ
55
56
57
58
59
|
# File 'lib/qti/v1/models/interactions/base_fill_blank_interaction.rb', line 55
def nq_blank_value(blank_id)
blank = canvas_fib_responses.find { |response| response[:id] == blank_id }
correct_choice = blank[:choices].find { |choice| choice[:id] == correct_answer_map[blank_id] }
correct_choice[:item_body]
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
|