require 'zip' require 'scormgen/version' module Scormgen class Generator MANIFEST = 'imsmanifest.xml' ZIP = 'module.zip' IGNORED_FILES = ['scorm_generator.rb', 'fire_app_log.txt', 'crossdomain.xml', 'config.rb', 'robots.txt', '.DS_Store'] def run(identifier=nil, name=nil) puts "scormgen #{Scormgen::VERSION}" @identifier = identifier.nil? ? default_identifier : identifier @name = name.nil? ? @identifier : name puts "Generating SCORM manifest for #{@name} (#{@identifier})" delete_previous_files list_files create_manifest zip_files puts "Done" end protected def delete_previous_files File.delete MANIFEST if File.exist? MANIFEST File.delete ZIP if File.exist? ZIP end def list_files @files = [] Dir.glob("**/*").each do |path| next if File.directory? path next if IGNORED_FILES.include? path @files << path end puts "#{@files.count} files found" end def default_identifier File.basename Dir.pwd end def create_defaults_from(args) @identifier = File.basename Dir.pwd @identifier = args[0] if args.count > 0 @name = @identifier @name = args[1] if args.count > 1 end def create_manifest imsmanifest = " ADL SCORM 2004 4th Edition <![CDATA[#{@name}]]> <![CDATA[#{@name}]]> " @files.each do |file| imsmanifest += " " end imsmanifest += " " file = File.open(MANIFEST, 'w') file.puts imsmanifest file.close @files << MANIFEST puts "#{MANIFEST} generated" end def zip_files puts "Zipping" Zip::File.open(ZIP, Zip::File::CREATE) do |zipfile| @files.each do |file| puts "Adding #{file} to zip" zipfile.add file, file end end puts "#{ZIP} generated" end end end