Module: Scorm2004::Manifest::VisitorPattern

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/scorm2004/manifest/visitor_pattern.rb', line 4

def self.included(base)
  base.class_eval do
    const_set('Error', Class.new(Scorm2004::Manifest::Error))
  end
end

Instance Method Details

#initialize(options = {}) ⇒ Object



10
11
12
# File 'lib/scorm2004/manifest/visitor_pattern.rb', line 10

def initialize(options = {})
  @options = options
end

#metadataNokogiri::XML::Node?

Returns The <metadata> element or nil.

Returns:

  • (Nokogiri::XML::Node, nil)

    The <metadata> element or nil



35
36
37
# File 'lib/scorm2004/manifest/visitor_pattern.rb', line 35

def 
  @el.at('./imscp:metadata', NS)
end

#to_hashObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/scorm2004/manifest/visitor_pattern.rb', line 23

def to_hash
  if respond_to? :content
    content
  else
    {}.merge(self.class.respond_to?(:attributes) ? attributes_hash : {})
      .merge(self.class.respond_to?(:children) ? children_hash : {})
      .merge(respond_to?(:href) ? {:href => href } : {})
      .reject { |k, v| v.nil? || v == [] || v == {} }
  end
end

#visit(el) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/scorm2004/manifest/visitor_pattern.rb', line 14

def visit(el)
  @el = el
  check_attributes if self.class.respond_to?(:attributes)
  do_visit         if self.respond_to?(:do_visit, true)
  visit_children   if self.class.respond_to?(:children)
  post_visit       if self.respond_to?(:post_visit, true)
  self
end