Class: Senkyoshi::ScormPackage
- Inherits:
-
Object
- Object
- Senkyoshi::ScormPackage
- Defined in:
- lib/senkyoshi/models/scorm_package.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#points_possible ⇒ Object
Returns the value of attribute points_possible.
Class Method Summary collapse
-
.correct_path(path, scorm_path) ⇒ Object
Returns file path with relative path to scorm package removed.
-
.find_scorm_item_paths(zip_file) ⇒ Object
Returns paths to scormItem files.
-
.find_scorm_items(zip_file) ⇒ Object
Returns array of parsed scormItem files.
-
.find_scorm_manifest(zip_file, scorm_item) ⇒ Object
Returns the zip file entry for the scorm package manifest, given a scormItem file.
-
.find_scorm_manifests(zip_file) ⇒ Object
Returns array of all scorm manifest files inside of blackboard export.
-
.find_scorm_paths(zip_file) ⇒ Object
Returns array of paths to scorm packages.
-
.get_entries(zip_file, manifest) ⇒ Object
Returns array of all zip file entries that belong in scorm package.
-
.get_scorm_packages(blackboard_export) ⇒ Object
Extracts scorm packages from a blackboard export zip file.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Removes all temp files if they exist.
-
#initialize(zip_file, manifest, scorm_item = nil) ⇒ ScormPackage
constructor
A new instance of ScormPackage.
-
#write_zip(export_name) ⇒ Object
Writes all entries to a zip file in a temporary directory and returns location of temporary file.
Constructor Details
#initialize(zip_file, manifest, scorm_item = nil) ⇒ ScormPackage
Returns a new instance of ScormPackage.
20 21 22 23 24 25 26 27 28 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 20 def initialize(zip_file, manifest, scorm_item = nil) @manifest = manifest @entries = ScormPackage.get_entries zip_file, manifest @points_possible = if scorm_item scorm_item.xpath( "/scormItem/gradebookInfo/@pointsPossible", ).text end end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
18 19 20 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 18 def entries @entries end |
#manifest ⇒ Object
Returns the value of attribute manifest.
18 19 20 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 18 def manifest @manifest end |
#points_possible ⇒ Object
Returns the value of attribute points_possible.
18 19 20 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 18 def points_possible @points_possible end |
Class Method Details
.correct_path(path, scorm_path) ⇒ Object
Returns file path with relative path to scorm package removed
107 108 109 110 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 107 def self.correct_path(path, scorm_path) corrected = path.gsub(scorm_path, "") corrected.slice(1, corrected.size) if corrected.start_with? "/" end |
.find_scorm_item_paths(zip_file) ⇒ Object
Returns paths to scormItem files
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 44 def self.find_scorm_item_paths(zip_file) Nokogiri::XML.parse( Senkyoshi.read_file(zip_file, "imsmanifest.xml"), ). xpath("//resource[@type='resource/x-plugin-scormengine']"). map { |r| r.xpath("./@bb:file").text } rescue Exceptions::MissingFileError => e if zip_file STDERR.puts "Blackboard export manifest file missing: #{zip_file.name}" end STDERR.puts e.to_s [] end |
.find_scorm_items(zip_file) ⇒ Object
Returns array of parsed scormItem files
62 63 64 65 66 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 62 def self.find_scorm_items(zip_file) find_scorm_item_paths(zip_file).map do |path| Nokogiri::XML.parse Senkyoshi.read_file(zip_file, path) end end |
.find_scorm_manifest(zip_file, scorm_item) ⇒ Object
Returns the zip file entry for the scorm package manifest, given a scormItem file
72 73 74 75 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 72 def self.find_scorm_manifest(zip_file, scorm_item) path = scorm_item.xpath("/scormItem/@mappedContentId").text zip_file.get_entry("#{path}/imsmanifest.xml") end |
.find_scorm_manifests(zip_file) ⇒ Object
Returns array of all scorm manifest files inside of blackboard export
80 81 82 83 84 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 80 def self.find_scorm_manifests(zip_file) find_scorm_items(zip_file).map do |scorm_item| find_scorm_manifest(zip_file, scorm_item) end end |
.find_scorm_paths(zip_file) ⇒ Object
Returns array of paths to scorm packages
89 90 91 92 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 89 def self.find_scorm_paths(zip_file) manifests = ScormPackage.find_scorm_manifests(zip_file) manifests.map { |manifest| File.dirname(manifest.name) } end |
.get_entries(zip_file, manifest) ⇒ Object
Returns array of all zip file entries that belong in scorm package
97 98 99 100 101 102 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 97 def self.get_entries(zip_file, manifest) zip_file.entries.select do |e| File.dirname(e.name).start_with?(File.dirname(manifest.name)) && !e.directory? end end |
.get_scorm_packages(blackboard_export) ⇒ Object
Extracts scorm packages from a blackboard export zip file
33 34 35 36 37 38 39 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 33 def self.get_scorm_packages(blackboard_export) find_scorm_items(blackboard_export). map do |item| manifest_entry = find_scorm_manifest(blackboard_export, item) ScormPackage.new blackboard_export, manifest_entry, item end end |
Instance Method Details
#cleanup ⇒ Object
Removes all temp files if they exist
137 138 139 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 137 def cleanup FileUtils.rm_r @dir unless @dir.nil? end |
#write_zip(export_name) ⇒ Object
Writes all entries to a zip file in a temporary directory and returns location of temporary file
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 116 def write_zip(export_name) @dir ||= Dir.mktmpdir scorm_path = File.dirname @manifest.name path = "#{@dir}/#{export_name}" Zip::File.open path, Zip::File::CREATE do |zip| @entries.each do |entry| if entry.file? zip.get_output_stream( ScormPackage.correct_path(entry.name, scorm_path), ) do |file| file.write(entry.get_input_stream.read) end end end end path end |