Class: XMP::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/xmp/namespace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xmp, namespace) ⇒ Namespace

:nodoc



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/xmp/namespace.rb', line 6

def initialize(xmp, namespace) # :nodoc
  @xmp = xmp
  @namespace = namespace.to_s

  @attributes = []
  embedded_attributes =
    xml.xpath("//rdf:Description").map { |d|
      d.attributes.values.
        select { |attr| attr.namespace ? attr.namespace.prefix.to_s : nil == @namespace }.
        map(&:name)
    }.flatten
  @attributes.concat embedded_attributes
  standalone_attributes = xml.xpath("//rdf:Description/#{@namespace}:*").
                              map(&:name)
  @attributes.concat standalone_attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/xmp/namespace.rb', line 27

def method_missing(method, *args)
  if has_attribute?(method)
    embedded_attribute(method) || standalone_attribute(method)
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

available attributes



4
5
6
# File 'lib/xmp/namespace.rb', line 4

def attributes
  @attributes
end

Instance Method Details

#inspectObject



23
24
25
# File 'lib/xmp/namespace.rb', line 23

def inspect
  "#<XMP::Namespace:#{@namespace}>"
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/xmp/namespace.rb', line 35

def respond_to?(method)
  has_attribute?(method) or super
end