Class: Scorm::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/scorm/resource.rb

Overview

A Resource is a representation/description of an actual resource (image, sco, pdf, etc…) in a SCORM package.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type, scorm_type, href = nil, metadata = nil, files = nil, dependencies = nil) ⇒ Resource

Returns a new instance of Resource.

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/scorm/resource.rb', line 14

def initialize(id, type, scorm_type, href = nil,  = nil, files = nil, dependencies = nil)
  raise InvalidManifest, 'Missing resource id' if id.nil?
  raise InvalidManifest, 'Missing resource type' if type.nil?
  breakpoint if scorm_type.nil?
  raise InvalidManifest, 'Missing resource scormType' if scorm_type.nil?
  @id = id.to_s
  @type = type.to_s
  @scorm_type = scorm_type.to_s
  @href = href.to_s || ''
  @metadata =  || Hash.new
  @files = files || []
  @dependencies = dependencies || []
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



12
13
14
# File 'lib/scorm/resource.rb', line 12

def dependencies
  @dependencies
end

#filesObject

Returns the value of attribute files.



11
12
13
# File 'lib/scorm/resource.rb', line 11

def files
  @files
end

#hrefObject

Returns the value of attribute href.



9
10
11
# File 'lib/scorm/resource.rb', line 9

def href
  @href
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/scorm/resource.rb', line 6

def id
  @id
end

#metadataObject

Returns the value of attribute metadata.



10
11
12
# File 'lib/scorm/resource.rb', line 10

def 
  @metadata
end

#scorm_typeObject

Returns the value of attribute scorm_type.



8
9
10
# File 'lib/scorm/resource.rb', line 8

def scorm_type
  @scorm_type
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/scorm/resource.rb', line 7

def type
  @type
end

Class Method Details

.from_xml(element) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scorm/resource.rb', line 28

def self.from_xml(element)
   = nil
  files = []
  REXML::XPath.each(element, 'file') do |file_el|
    files << element.attribute('xml:base').to_s + file_el.attribute('href').to_s
  end
  dependencies = []
  REXML::XPath.each(element, 'dependency') do |dep_el|
    dependencies << dep_el.attribute('identifierref').to_s
  end

  res = self.new(
    element.attribute('identifier'), 
    element.attribute('type'), 
    element.attribute('scormType', 'adlcp') || element.attribute('scormtype', 'adlcp'),
    element.attribute('xml:base').to_s + element.attribute('href').to_s,
    ,
    files,
    dependencies)
end