Class: Qti::V1::Models::AssessmentItem
- Inherits:
-
Base
show all
- Defined in:
- lib/qti/v1/models/assessment_item.rb
Instance Attribute Summary collapse
Attributes inherited from Models::Base
#manifest, #package_root, #path
Instance Method Summary
collapse
Methods inherited from Base
#qti_version, #return_inner_content!, #sanitize_attributes, #sanitize_attributes_by_node
#css_with_single_check, from_path!, #parse_html, #parse_xml, #preprocess_xml_doc, #raise_unsupported, #remap_href_path, #sanitize_content!, #xpath_with_single_check
Constructor Details
#initialize(item, package_root = nil, resource = nil) ⇒ AssessmentItem
Returns a new instance of AssessmentItem.
9
10
11
12
13
14
|
# File 'lib/qti/v1/models/assessment_item.rb', line 9
def initialize(item, package_root = nil, resource = nil)
@doc = item
@path = item.document.url
@resource = resource
self.package_root = package_root
end
|
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
5
6
7
|
# File 'lib/qti/v1/models/assessment_item.rb', line 5
def doc
@doc
end
|
#resource ⇒ Object
Returns the value of attribute resource.
5
6
7
|
# File 'lib/qti/v1/models/assessment_item.rb', line 5
def resource
@resource
end
|
Instance Method Details
#answer_feedback ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/qti/v1/models/assessment_item.rb', line 131
def answer_feedback
@answer_feedback ||= interaction_model.answer_feedback&.map do |answer|
duped = answer.dup
duped[:feedback] = sanitize_content!(duped[:feedback])
duped
end
end
|
#calculator_type ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/qti/v1/models/assessment_item.rb', line 87
def calculator_type
@calculator_type ||= begin
if calculator_type_metadata?
calculator_type_metadata_label = qti_metadata_children.children.find do |node|
node.text == 'calculator_type'
end
calculator_type_metadata_label.next.text
end
end
end
|
98
99
100
101
102
103
104
105
106
|
# File 'lib/qti/v1/models/assessment_item.rb', line 98
def calculator_type_metadata?
if @doc.at_xpath('.//xmlns:qtimetadata').present?
qti_metadata_children.children.find do |node|
node.text == 'calculator_type'
end.present?
else
false
end
end
|
#decvar_maxvalue ⇒ Object
108
109
110
111
|
# File 'lib/qti/v1/models/assessment_item.rb', line 108
def decvar_maxvalue
@doc.at_xpath('.//xmlns:decvar/@maxvalue')&.value&.to_i ||
@doc.at_xpath('.//xmlns:decvar/@defaultval')&.value&.to_i || 0
end
|
#feedback ⇒ Object
127
128
129
|
# File 'lib/qti/v1/models/assessment_item.rb', line 127
def feedback
@feedback ||= interaction_model.canvas_item_feedback&.transform_values { |v| sanitize_content!(v) }
end
|
48
49
50
51
|
# File 'lib/qti/v1/models/assessment_item.rb', line 48
def has_points_possible_qti_metadata? warn "DEPRECATED: '#{__method__}' is renamed to 'points_possible_qti_metadata?'."
points_possible_qti_metadata?
end
|
#identifier ⇒ Object
26
27
28
|
# File 'lib/qti/v1/models/assessment_item.rb', line 26
def identifier
@identifier ||= @doc.attribute('ident').value
end
|
#interaction_model ⇒ Object
117
118
119
120
121
|
# File 'lib/qti/v1/models/assessment_item.rb', line 117
def interaction_model
@interaction_model ||= begin
V1::Models::Interactions.interaction_model(@doc, self)
end
end
|
#item_body ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/qti/v1/models/assessment_item.rb', line 16
def item_body
@item_body ||= begin
node = @doc.dup
presentation = node.at_xpath('.//xmlns:presentation')
mattext = presentation.at_xpath('.//xmlns:mattext')
prompt = sanitize_attributes(return_inner_content!(mattext))
sanitize_content!(prompt)
end
end
|
#parent_stimulus_item_ident ⇒ Object
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/qti/v1/models/assessment_item.rb', line 76
def parent_stimulus_item_ident
@parent_stimulus_item_ident ||= begin
if parent_stimulus_item_ident_metadata?
parent_stimulus_item_ident_label = qti_metadata_children.children.find do |node|
node.text == 'parent_stimulus_item_ident'
end
parent_stimulus_item_ident_label.next.text
end
end
end
|
66
67
68
69
70
71
72
73
74
|
# File 'lib/qti/v1/models/assessment_item.rb', line 66
def parent_stimulus_item_ident_metadata?
if @doc.at_xpath('.//xmlns:qtimetadata').present?
qti_metadata_children.children.find do |node|
node.text == 'parent_stimulus_item_ident'
end.present?
else
false
end
end
|
#points_possible ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/qti/v1/models/assessment_item.rb', line 53
def points_possible
@points_possible ||= begin
if points_possible_qti_metadata?
points_possible_label = qti_metadata_children.children.find do |node|
node.text == 'points_possible'
end
points_possible_label.next.text
else
1
end
end
end
|
38
39
40
41
42
43
44
45
|
# File 'lib/qti/v1/models/assessment_item.rb', line 38
def points_possible_qti_metadata?
if @doc.at_xpath('.//xmlns:qtimetadata').present?
points_possible_label = qti_metadata_children.children.find { |node| node.text == 'points_possible' }
points_possible_label.present?
else
false
end
end
|
34
35
36
|
# File 'lib/qti/v1/models/assessment_item.rb', line 34
def qti_metadata_children
@doc.at_xpath('.//xmlns:qtimetadata')&.children
end
|
#rcardinality ⇒ Object
113
114
115
|
# File 'lib/qti/v1/models/assessment_item.rb', line 113
def rcardinality
@rcardinality ||= @doc.at_xpath('.//xmlns:response_lid/@rcardinality').value
end
|
#scoring_data_structs ⇒ Object
123
124
125
|
# File 'lib/qti/v1/models/assessment_item.rb', line 123
def scoring_data_structs
@scoring_data_structs ||= interaction_model.scoring_data_structs
end
|
#title ⇒ Object
30
31
32
|
# File 'lib/qti/v1/models/assessment_item.rb', line 30
def title
@title ||= @doc.attribute('title')&.value
end
|