Class: Scorm::Manifest
- Inherits:
-
Object
- Object
- Scorm::Manifest
- Defined in:
- lib/scorm/manifest.rb
Constant Summary collapse
- SUPPORTED_VERSIONS =
Versions of the SCORM standard that is supported when running in strict mode. When not running in strict mode, the library will not care about the version specified in the package manifest and will simply try its best to parse the information that it finds.
['2004 3rd Edition', 'CAM 1.3', '1.2']
- MANIFEST_FILES =
List of XML and XML Schema files that are part of the manifest for the package.
%w(imsmanifest.xml adlcp_rootv1p2.xsd ims_xml.xsd imscp_rootv1p1p2.xsd imsmd_rootv1p2p1.xsd)
- RESOURCES_BLACKLIST =
Files that might be present in a package, but that should not be interprested as resources. All files starting with a “.” (i.e. hidden files) is also implicitly included in this list.
[ '__MACOSX', 'desktop.ini', 'Thumbs.db' ].concat(MANIFEST_FILES)
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#default_organization ⇒ Object
Returns the value of attribute default_organization.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#organizations ⇒ Object
Returns the value of attribute organizations.
-
#resources(options = nil) ⇒ Object
Returns the value of attribute resources.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#schema_version ⇒ Object
Returns the value of attribute schema_version.
Instance Method Summary collapse
-
#initialize(package, manifest_data) ⇒ Manifest
constructor
A new instance of Manifest.
- #sco(item, attribute = nil) ⇒ Object
Constructor Details
#initialize(package, manifest_data) ⇒ Manifest
Returns a new instance of Manifest.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/scorm/manifest.rb', line 36 def initialize(package, manifest_data) @xmldoc = REXML::Document.new(manifest_data) @package = package @metadata = Scorm::Metadata.new @organizations = Hash.new @resources = Hash.new # Manifest identifier @identifier = @xmldoc.root.attribute('identifier').to_s # Read metadata if = REXML::XPath.first(@xmldoc.root, '/manifest/metadata') # Read <schema> and <schemaversion> schema_el = REXML::XPath.first(, 'schema') schemaversion_el = REXML::XPath.first(, 'schemaversion') @schema = schema_el.text.to_s unless schema_el.nil? @schema_version = schemaversion_el.text.to_s unless schemaversion_el.nil? if @package.[:strict] if (@schema != 'ADL SCORM') || (!SUPPORTED_VERSIONS.include?(@schema_version)) raise InvalidManifest, "Sorry, unsupported SCORM-version (#{schema_el.text.to_s} #{schemaversion_el.text.to_s}), try turning strict parsing off." end end # Find a <lom> element... lom_el = nil if adlcp_location = REXML::XPath.first(, 'adlcp:location') # Read external metadata file = REXML::Document.new(package.file(adlcp_location.text.to_s)) if .nil? || (.root.name != 'lom') raise InvalidManifest, "Invalid external metadata file (#{adlcp_location.text.to_s})." else lom_el = .root end else # Read inline metadata lom_el = REXML::XPath.first(, 'lom') || REXML::XPath.first(, 'lom:lom') end # Read lom metadata if lom_el @metadata = Scorm::Metadata.from_xml(lom_el) end end # Read organizations if organizations_el = REXML::XPath.first(@xmldoc.root, '/manifest/organizations') default_organization_id = organizations_el.attribute('default').to_s REXML::XPath.each(@xmldoc.root, '/manifest/organizations/organization') do |el| org = Scorm::Organization.from_xml(el) @organizations[org.id.to_s] = org end # Set the default organization @default_organization = @organizations[default_organization_id] raise InvalidManifest, "No default organization (#{default_organization_id})." if @default_organization.nil? else raise InvalidManifest, 'Missing organizations element.' end # Read resources REXML::XPath.each(@xmldoc.root, '/manifest/resources/resource') do |el| res = Scorm::Resource.from_xml(el) @resources[res.id] = res end # Read additional resources as assets (this is a fix for packages that # don't correctly specify all resource dependencies in the manifest). @package.files.each do |file| next if File.directory?(file) next if RESOURCES_BLACKLIST.include?(File.basename(file)) next if File.basename(file) =~ /^\./ next unless self.resources(:with_file => file).empty? next unless self.resources(:href => file).empty? res = Scorm::Resource.new(file, 'webcontent', 'asset', file, nil, [file]) @resources[file] = res end # Read (optional) base url for resources resources_el = REXML::XPath.first(@xmldoc.root, '/manifest/resources') @base_url = (resources_el.attribute('xml:base') || '').to_s # Read sub-manifests #REXML::XPath. end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
32 33 34 |
# File 'lib/scorm/manifest.rb', line 32 def base_url @base_url end |
#default_organization ⇒ Object
Returns the value of attribute default_organization.
30 31 32 |
# File 'lib/scorm/manifest.rb', line 30 def default_organization @default_organization end |
#identifier ⇒ Object
Returns the value of attribute identifier.
27 28 29 |
# File 'lib/scorm/manifest.rb', line 27 def identifier @identifier end |
#metadata ⇒ Object
Returns the value of attribute metadata.
28 29 30 |
# File 'lib/scorm/manifest.rb', line 28 def @metadata end |
#organizations ⇒ Object
Returns the value of attribute organizations.
29 30 31 |
# File 'lib/scorm/manifest.rb', line 29 def organizations @organizations end |
#resources(options = nil) ⇒ Object
Returns the value of attribute resources.
31 32 33 |
# File 'lib/scorm/manifest.rb', line 31 def resources @resources end |
#schema ⇒ Object
Returns the value of attribute schema.
33 34 35 |
# File 'lib/scorm/manifest.rb', line 33 def schema @schema end |
#schema_version ⇒ Object
Returns the value of attribute schema_version.
34 35 36 |
# File 'lib/scorm/manifest.rb', line 34 def schema_version @schema_version end |
Instance Method Details
#sco(item, attribute = nil) ⇒ Object
148 149 150 151 152 |
# File 'lib/scorm/manifest.rb', line 148 def sco(item, attribute = nil) resource = self.resources(:id => item.resource_id).first resource = (resource && resource.scorm_type == 'sco') ? resource : nil return (resource && attribute) ? resource.send(attribute) : resource end |