Class: Qti::V1::Models::Interactions::FillBlankInteraction
Instance Attribute Summary
#node
Attributes inherited from Models::Base
#doc, #manifest, #package_root, #path, #resource
Class Method Summary
collapse
Instance Method Summary
collapse
#blank_id, #blank_value, #canvas_blank_id, #canvas_custom_fitb?, #canvas_fib_response_ids, #canvas_fib_responses, #canvas_stem_items, #nq_blank_id, #nq_blank_value, #stem_blank, #stem_text
#answer_feedback, canvas_custom_fitb?, #canvas_item_feedback, canvas_multiple_fib?, #initialize, #locked_choices, maybe_question_type, new_quizzes_fib?, question_type, #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
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
#answers ⇒ Object
76
77
78
79
80
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 76
def answers
@answers ||= answer_nodes.map do |node|
V1::Models::Choices::FillBlankChoice.new(node, self)
end
end
|
#blanks ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 56
def blanks
if node.at_xpath('.//xmlns:render_choice').present?
canvas_blanks
else
qti_standard_blanks
end
end
|
#canvas_blanks ⇒ Object
64
65
66
67
68
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 64
def canvas_blanks
node.xpath('.//xmlns:response_label').map do |blank|
{ id: blank.attributes['ident']&.value }
end
end
|
#canvas_multiple_fib? ⇒ 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
|
#correct_answer_map ⇒ Object
128
129
130
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 128
def correct_answer_map
@correct_answer_map ||= super
end
|
#new_quizzes_fib? ⇒ Boolean
33
34
35
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 33
def new_quizzes_fib?
@new_quizzes_fib ||= BaseInteraction.new_quizzes_fib?(@node)
end
|
#qti_standard_blanks ⇒ Object
70
71
72
73
74
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 70
def qti_standard_blanks
node.xpath('.//xmlns:response_str').map do |blank|
{ id: blank.attributes['ident']&.value }
end
end
|
#qti_stem_items ⇒ Object
45
46
47
48
49
50
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 45
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 ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 82
def scoring_data_structs
@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,
scoring_algorithm: scoring_data_algorithm(value_node),
answer_type: scoring_data_answer_type(value_node),
scoring_options: scoring_data_options(value_node)
)
end
end
|
#single_fill_in_blank? ⇒ Boolean
52
53
54
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 52
def single_fill_in_blank?
!canvas_multiple_fib? && blanks.count == 1
end
|
#stem_items ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 37
def stem_items
if canvas_multiple_fib?
canvas_stem_items(node.at_xpath('.//xmlns:mattext').text)
else
qti_stem_items
end
end
|
#wordbank_allow_reuse? ⇒ Boolean
103
104
105
106
107
108
109
110
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 103
def wordbank_allow_reuse?
return unless wordbank_answer_present?
wordbank_struct = scoring_data_structs.find { |struct| struct.answer_type == 'wordbank' }
return false unless wordbank_struct.scoring_options['allow_reuse'] == 'true'
true
end
|
#wordbank_answer_present? ⇒ Boolean
97
98
99
100
101
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 97
def wordbank_answer_present?
return false unless first_wordbank_answer
true
end
|
#wordbank_choices ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/qti/v1/models/interactions/fill_blank_interaction.rb', line 112
def wordbank_choices
return unless wordbank_answer_present?
choices = Set.new
wordbank_answers = all_wordbank_answers.map do |node|
V1::Models::Choices::FillBlankChoice.new(node, self)
end
wordbank_answers.each do |wordbank_answer|
choices.add({ id: wordbank_answer.identifier, item_body: wordbank_answer.item_body })
end
choices.to_a
end
|