canvas_qti_to_learnosity_converter 0.1.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b08edcaa5b1202695605345f102ecd6999daf9da1e93afe4be7f3fac421e1607
|
4
|
+
data.tar.gz: dac787cd08b5d12ba9f2612db7b7b05d5d8421d1ac49775790f3469af8fca511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6628bda0a17f0686f773cbf651fe1b19dd427d466440e43ba2ec3759e60d9f03d8f8b67544716f13239d776d6cfda201c1b427562d9e2aedf116e244b3ef239
|
7
|
+
data.tar.gz: 278c0aed069d6b31d91088c764010c288ebefe4a818e4049d87b489ed0f1e38d796192bedb05afae538028165643a09dda55003eeab523737fceb23a5f66576b
|
@@ -2,6 +2,7 @@ require "nokogiri"
|
|
2
2
|
require "forwardable"
|
3
3
|
require "ostruct"
|
4
4
|
require "zip"
|
5
|
+
require "uri"
|
5
6
|
|
6
7
|
module CanvasQtiToLearnosityConverter
|
7
8
|
class CanvasQuestionTypeNotSupportedError < RuntimeError
|
@@ -150,37 +151,65 @@ module CanvasQtiToLearnosityConverter
|
|
150
151
|
type: "mcq",
|
151
152
|
validation: extract_multiple_answers_validation(item),
|
152
153
|
})
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.add_files_to_assets(assets, path, text)
|
157
|
+
text.scan(/%24IMS-CC-FILEBASE%24\/([^"]+)/).flatten.each do |asset_path|
|
158
|
+
decoded_path = URI.unescape(asset_path)
|
159
|
+
assets[decoded_path] ||= []
|
160
|
+
assets[decoded_path].push(path)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.convert_item(qti_quiz, assets, item_index)
|
165
|
+
type = extract_type(qti_quiz)
|
166
|
+
|
167
|
+
question = case type
|
168
|
+
when :multiple_choice_question
|
169
|
+
convert_multiple_choice(qti_quiz)
|
170
|
+
when :true_false_question
|
171
|
+
convert_multiple_choice(qti_quiz)
|
172
|
+
when :multiple_answers_question
|
173
|
+
convert_multiple_answers(qti_quiz)
|
174
|
+
else
|
175
|
+
raise CanvasQuestionTypeNotSupportedError
|
176
|
+
end
|
177
|
+
|
178
|
+
add_files_to_assets(
|
179
|
+
assets,
|
180
|
+
[item_index, :stimulus],
|
181
|
+
question.stimulus
|
182
|
+
)
|
183
|
+
|
184
|
+
question.options.each.with_index do |option, index|
|
185
|
+
add_files_to_assets(
|
186
|
+
assets,
|
187
|
+
[item_index, :options, index, "label"],
|
188
|
+
option["label"]
|
189
|
+
)
|
190
|
+
end
|
191
|
+
|
192
|
+
question
|
193
|
+
end
|
194
|
+
|
195
|
+
def self.convert(qti, assets)
|
170
196
|
quiz = CanvasQtiQuiz.new(qti_string: qti)
|
171
|
-
|
197
|
+
assessment = quiz.css("assessment")
|
198
|
+
ident = assessment.attribute("ident").value
|
199
|
+
assets[ident] = {}
|
200
|
+
|
201
|
+
items = quiz.css("item").map.with_index do |item, index|
|
172
202
|
begin
|
173
203
|
quiz_item = CanvasQtiQuizQuestion.new(qti_string: item.to_html)
|
174
|
-
convert_item(quiz_item)
|
204
|
+
convert_item(quiz_item, assets[ident], index)
|
175
205
|
rescue CanvasQuestionTypeNotSupportedError
|
176
206
|
nil
|
177
207
|
end
|
178
208
|
end.compact
|
179
209
|
|
180
|
-
assessment = quiz.css("assessment")
|
181
210
|
{
|
182
211
|
title: assessment.attribute("title").value,
|
183
|
-
ident:
|
212
|
+
ident: ident,
|
184
213
|
items: items,
|
185
214
|
}
|
186
215
|
end
|
@@ -211,11 +240,17 @@ module CanvasQtiToLearnosityConverter
|
|
211
240
|
manifest = entry.get_input_stream.read
|
212
241
|
parsed_manifest = Nokogiri.XML(manifest, &:noblanks)
|
213
242
|
paths = imscc_quiz_paths(parsed_manifest)
|
214
|
-
|
243
|
+
|
244
|
+
assets = {}
|
245
|
+
converted_assesments = paths.map do |qti_path|
|
215
246
|
qti = zip_file.find_entry(qti_path).get_input_stream.read
|
216
|
-
to_native_types(convert(qti))
|
247
|
+
to_native_types(convert(qti, assets))
|
217
248
|
end
|
218
|
-
|
249
|
+
|
250
|
+
{
|
251
|
+
assessments: converted_assesments,
|
252
|
+
assets: assets,
|
253
|
+
}
|
219
254
|
end
|
220
255
|
end
|
221
256
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canvas_qti_to_learnosity_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atomic Jolt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.6
|
139
|
+
rubygems_version: 2.7.6
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Converts canvas qti to learnosity JSON
|