scorm2004-manifest

Description

scorm2004-manifest is a Ruby gem that provides a manifest file parser for SCORM 2004 4th edition. It parses and validates the manifest file according to SCORM 2004 4th Edition Content Aggregation Model (CAM) Version 1.1. After parsing and validating, it builds an object tree that captures XML’s hierarchical structure.

Installation

To install scorm2004-manifest, use the following command:

$ gem install scorm2004-manifest

Requirements

Synopsis

require 'scorm2004-manifest'

# Parse a manifest file
begin
  manifest = Scorm2004::Manifest(open('imsmanifest.xml'))
rescue Scorm2004::Manifest::Error => e
  # An exception will be raised if validation fails.
  # The exception 'e' will be an instance of
  # Scorm2004::Manifest::Error's subclass.
end

# Traverse an object tree
manifest.identifier        # => "LMSTestPackage_CM-01"
manifest.version           # => "1.1.1"
organizations = manifest.organizations
organization = organizations.organizations[0]
organization.identifier    # => "CM-01"
organization.title.content # => "LMS Test Content Package CM-01 "
item_0 = organization.items[0]
item_0.title.content       # => "Activity 1"
item_0.identifier          # => "activity_1"
item_0.identifierref       # => "SEQ01"
item_0.parameters          # => "?tc=CM-01&act=1"
item_0.sequencing.limit_conditions.attempt_absolute_duration_limit
# => "P5Y6M4DT12H30M58S"
item_0.presentation.navigation_interface.hide_lmsuis.map(&:content)
# => ["continue", "previous", "suspendAll"]
# ...

For every XML element in a manifest file, XML attributes and child elements defined in Content Aggregation Model can be accessed using accessor methods whose names are underscored. Namespace prefixes are omitted from the accessor methods, except for either adlseq_objectives, adlseq_objective, or adlseq_map_info. If an element may have multiple child elements, the accessor method for the child elements will be pluralized. For example, <organizations> element has one or more <organization> elements.

# <organizations> can be accessed using the organizations
# method of the manifest object.
organizations = manifest.organizations

# The <organization> collection of the <organizations>
# element can be accessed using the organizations method
# of the organizations object. To get the first
# <organization> of the <organizations>, use the
# following expression.
organization_0 = organizations.organizations[0]

Each parsed element also responds to the to_hash method. Using this method, you can convert your manifest file into Hash or more useful forms.

json_manifest = Scorm2004::Manifest(open('imsmanifest.xml')).to_hash.to_json

Documentation

To generate scorm2004-manifest’s document set, use the following command:

$ git clone git://github.com/tnoda/scorm2004-manifest.git
$ cd scorm2004-manifest
$ rake yard

The document set will be generated under the doc directory.

Contributing to scorm2004-manifest

Copyright © 2012 Takahiro Noda. See LICENSE.txt for further details.