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
- SHA1:
3
- metadata.gz: 53ff60c56cd54498580e8d5d8846ead76b556e34
4
- data.tar.gz: 2349315a79fcc2ca9102e37a1586256b46dc9383
2
+ SHA256:
3
+ metadata.gz: b08edcaa5b1202695605345f102ecd6999daf9da1e93afe4be7f3fac421e1607
4
+ data.tar.gz: dac787cd08b5d12ba9f2612db7b7b05d5d8421d1ac49775790f3469af8fca511
5
5
  SHA512:
6
- metadata.gz: 70e0e8ab32260a9287883ac49a48064014fc8a9f19b5389b30c28ac753cacd86b3f680138d21a49c196f0b42a0ecfd9819c829ae253f525ce0f6b9f19249e7a0
7
- data.tar.gz: 8403b74e41dee286016e31fc84e82b2197f7aa139756aae2a1f9b62cb75328ac69a54a4438d4379dc22846e105419f0610af74989b935a25f3d9ac27ce3d5720
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
- end
154
-
155
- def self.convert_item(qti_quiz)
156
- type = extract_type(qti_quiz)
157
- case type
158
- when :multiple_choice_question
159
- convert_multiple_choice(qti_quiz)
160
- when :true_false_question
161
- convert_multiple_choice(qti_quiz)
162
- when :multiple_answers_question
163
- convert_multiple_answers(qti_quiz)
164
- else
165
- raise CanvasQuestionTypeNotSupportedError
166
- end
167
- end
168
-
169
- def self.convert(qti)
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
- items = quiz.css("item").map do |item|
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: assessment.attribute("ident").value,
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
- result = paths.map do |qti_path|
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
- result
249
+
250
+ {
251
+ assessments: converted_assesments,
252
+ assets: assets,
253
+ }
219
254
  end
220
255
  end
221
256
  end
@@ -1,3 +1,3 @@
1
1
  module CanvasQtiToLearnosityConverter
2
- VERSION = "0.1.5"
2
+ VERSION = "1.0.0"
3
3
  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.1.5
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-04-23 00:00:00.000000000 Z
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.11
139
+ rubygems_version: 2.7.6
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Converts canvas qti to learnosity JSON