Class: XMP::Namespace

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Convenience

#[], #include?, #respond_to_missing?, #to_h

Constructor Details

#initialize(document, namespace) ⇒ Namespace

Returns a new instance of Namespace.



5
6
7
8
9
10
11
# File 'lib/xmp/namespace.rb', line 5

def initialize(document, namespace)
  @document, @namespace  = document, namespace
  @standalone_attributes = xml.xpath("//rdf:Description/#{namespace}:*").map(&:name)
  @embedded_attributes   = xml.xpath('//rdf:Description').flat_map do |description|
    description.attributes.values.select { |attr| attr.namespace.prefix.to_s == namespace }.map(&:name)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class XMP::Convenience

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



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

def document
  @document
end

#embedded_attributesObject (readonly)

Returns the value of attribute embedded_attributes.



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

def embedded_attributes
  @embedded_attributes
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#standalone_attributesObject (readonly)

Returns the value of attribute standalone_attributes.



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

def standalone_attributes
  @standalone_attributes
end

Instance Method Details

#attributesObject



13
14
15
# File 'lib/xmp/namespace.rb', line 13

def attributes
  @attributes ||= (standalone_attributes + embedded_attributes).uniq
end