Class: AVM::XMP
- Inherits:
-
Object
- Object
- AVM::XMP
- Defined in:
- lib/avm/xmp.rb
Overview
An XMP document wrapper, providing namespace handling and document reference assistance.
Constant Summary collapse
- PREFIXES =
{ 'dc' => 'Dublin Core', 'Iptc4xmpCore' => 'IPTC', 'photoshop' => 'Photoshop', 'avm' => 'AVM' }
- REQUIRED_NAMESPACES =
{ :x => "adobe:ns:meta/", :rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", :dc => "http://purl.org/dc/elements/1.1/", :photoshop => "http://ns.adobe.com/photoshop/1.0/", :avm => "http://www.communicatingastronomy.org/avm/1.0/", :Iptc4xmpCore => "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" }
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Class Method Summary collapse
Instance Method Summary collapse
- #at_xpath(path, node = doc) ⇒ Object
- #ensure_xmlns(string) ⇒ Object (also: #%)
- #ensure_xpath(path) ⇒ Object
- #get_refs {|Hash[[ :dublin_core, :iptc, :photoshop, :avm ]| ... } ⇒ Object
-
#initialize(doc = nil) ⇒ XMP
constructor
A new instance of XMP.
- #namespaces ⇒ Object
- #search(path, node = doc) ⇒ Object
Constructor Details
#initialize(doc = nil) ⇒ XMP
Returns a new instance of XMP.
25 26 27 28 29 30 31 32 |
# File 'lib/avm/xmp.rb', line 25 def initialize(doc = nil) @doc = doc || empty_xml_doc raise StandardError.new('not a Nokogiri node') if !@doc.kind_of?(::Nokogiri::XML::Node) ensure_namespaces! ensure_descriptions_findable! end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
23 24 25 |
# File 'lib/avm/xmp.rb', line 23 def doc @doc end |
Class Method Details
.from_string(string) ⇒ Object
38 39 40 |
# File 'lib/avm/xmp.rb', line 38 def self.from_string(string) new(Nokogiri::XML(string)) end |
Instance Method Details
#at_xpath(path, node = doc) ⇒ Object
56 57 58 |
# File 'lib/avm/xmp.rb', line 56 def at_xpath(path, node = doc) node.at_xpath(*ensure_xpath(path)) end |
#ensure_xmlns(string) ⇒ Object Also known as: %
42 43 44 |
# File 'lib/avm/xmp.rb', line 42 def ensure_xmlns(string) string.gsub(%r{([</@])(\w+):}) { |all, matches| $1 + (prefix_map[$2] || $2) + ':' } end |
#ensure_xpath(path) ⇒ Object
48 49 50 |
# File 'lib/avm/xmp.rb', line 48 def ensure_xpath(path) [ ensure_xmlns(path), namespaces ] end |
#get_refs {|Hash[[ :dublin_core, :iptc, :photoshop, :avm ]| ... } ⇒ Object
34 35 36 |
# File 'lib/avm/xmp.rb', line 34 def get_refs yield Hash[[ :dublin_core, :iptc, :photoshop, :avm ].collect { |key| [ key, send(key) ] }] end |
#namespaces ⇒ Object
60 61 62 |
# File 'lib/avm/xmp.rb', line 60 def namespaces @namespaces ||= doc.document.collect_namespaces end |
#search(path, node = doc) ⇒ Object
52 53 54 |
# File 'lib/avm/xmp.rb', line 52 def search(path, node = doc) node.search(*ensure_xpath(path)) end |