Class: Scorm::Command::Bundle

Inherits:
Base
  • Object
show all
Defined in:
lib/scorm/commands/bundle.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #autodetected_package

Instance Method Summary collapse

Methods inherited from Base

#display, #error, #extract_option, #extract_package, #initialize

Constructor Details

This class inherits a constructor from Scorm::Command::Base

Instance Method Details

#indexObject


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/scorm/commands/bundle.rb', line 3

def index
  name = args.shift.strip rescue '.'
  unless File.exist?(File.join(File.expand_path(name), 'imsmanifest.xml'))
    raise(CommandFailed, "Invalid package, didn't find any imsmanifest.xml file.")
  end
  
  outname = File.basename(File.expand_path(name)) + '.zip'
  
  require 'zip/zip'
  Zip::ZipFile.open(outname, Zip::ZipFile::CREATE) do |zipfile|
    Scorm::Package.open(name) do |pkg|
      Scorm::Manifest::MANIFEST_FILES.each do |file|
        zipfile.get_output_stream(file) {|f| f.write(pkg.file(file)) }
        display file
      end
      files = pkg.manifest.resources.map {|r| r.files }.flatten.uniq
      files.each do |file|
        zipfile.get_output_stream(file) {|f| f.write(pkg.file(file)) }
        display file
      end
    end
  end
  
  display "Created new SCORM package \"#{outname}\"."
end