Class: CanvasQtiToLearnosityConverter::QuizQuestion
- Inherits:
-
Object
- Object
- CanvasQtiToLearnosityConverter::QuizQuestion
show all
- Extended by:
- Forwardable
- Defined in:
- lib/canvas_qti_to_learnosity_converter/questions/question.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of QuizQuestion.
8
9
10
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 8
def initialize(xml)
@xml = xml
end
|
Instance Method Details
#convert(assets, path) ⇒ Object
59
60
61
62
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 59
def convert(assets, path)
object = to_learnosity
add_learnosity_assets(assets, path, object)
end
|
#dynamic_content_data ⇒ Object
31
32
33
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 31
def dynamic_content_data()
{}
end
|
23
24
25
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 23
def (mattext_node)
mattext_node.content
end
|
17
18
19
20
21
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 17
def
@xml.css(%{ item > itemmetadata > qtimetadata >
qtimetadatafield > fieldlabel:contains("points_possible")})
&.first&.next&.text&.to_f || 1.0
end
|
12
13
14
15
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 12
def ()
mattext = @xml.css("item > presentation > material > mattext").first
(mattext)
end
|
#make_identifier ⇒ Object
27
28
29
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 27
def make_identifier()
SecureRandom.uuid
end
|
#process_assets!(assets, path, text) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/canvas_qti_to_learnosity_converter/questions/question.rb', line 35
def process_assets!(assets, path, text)
doc = Nokogiri::XML.fragment(text)
changed = false
doc.css("img").each do |node|
source = node["src"]
next if !source
source = URI::DEFAULT_PARSER.unescape(source)
if /^\$IMS-CC-FILEBASE\$(.*)/.match(source) || /^((?!https?:).*)/.match(source)
if source.start_with?("$IMS-CC-FILEBASE$")
path = ''
end
asset_path = $1
asset_path = asset_path.split("?").first.gsub(/^\//, '')
asset_path = File.join(path, asset_path)
clean_ext = File.extname(asset_path).gsub(/[^a-z0-9_.-]/i, '')
assets[asset_path] ||= "#{SecureRandom.uuid}#{clean_ext}"
node["src"] = "___EXPORT_ROOT___/assets/#{assets[asset_path]}"
changed = true
end
end
text.replace(doc.to_xml) if changed
end
|