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.
5 6 7 8 9 10 11 12 13 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 5 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.
3 4 5 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 3 def entries @entries end |
#manifest ⇒ Object
Returns the value of attribute manifest.
3 4 5 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 3 def manifest @manifest end |
#points_possible ⇒ Object
Returns the value of attribute points_possible.
3 4 5 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 3 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
92 93 94 95 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 92 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 29 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
47 48 49 50 51 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 47 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
57 58 59 60 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 57 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
65 66 67 68 69 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 65 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
74 75 76 77 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 74 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
82 83 84 85 86 87 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 82 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
18 19 20 21 22 23 24 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 18 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
122 123 124 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 122 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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/senkyoshi/models/scorm_package.rb', line 101 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 |