Class: XMPR::XMP
- Inherits:
-
Object
- Object
- XMPR::XMP
- Defined in:
- lib/xmpr.rb
Instance Attribute Summary collapse
-
#xml ⇒ Object
readonly
Nokogiri document of parsed xml.
Instance Method Summary collapse
- #[](namespace_or_name, name = nil, **options) ⇒ Object
-
#initialize(source) ⇒ XMP
constructor
A new instance of XMP.
- #to_hash ⇒ Object
Constructor Details
#initialize(source) ⇒ XMP
Returns a new instance of XMP.
52 53 54 55 |
# File 'lib/xmpr.rb', line 52 def initialize(source) require "nokogiri" @xml = Nokogiri::XML(source) end |
Instance Attribute Details
#xml ⇒ Object (readonly)
Nokogiri document of parsed xml
50 51 52 |
# File 'lib/xmpr.rb', line 50 def xml @xml end |
Instance Method Details
#[](namespace_or_name, name = nil, **options) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/xmpr.rb', line 57 def [](namespace_or_name, name=nil, **) if name namespace = namespace_or_name else namespace, name = DEFAULT_NAMESPACE, namespace_or_name end if NAMESPACES.has_key? namespace namespace = NAMESPACES[namespace] end (namespace, name) || standalone_attribute(namespace, name, **) end |
#to_hash ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/xmpr.rb', line 72 def to_hash {}.tap do |hash| xml.at("//rdf:Description", NAMESPACES).attributes.each do |(_, attribute)| hash[attribute.namespace.href] ||= {} hash[attribute.namespace.href][attribute.name] = attribute.value end xml.xpath("//rdf:Description/*", NAMESPACES).each do |element| hash[element.namespace.href] ||= {} hash[element.namespace.href][element.name] = standalone_value(element, lang: nil) end end end |