class EmbedXMP::XMP
XMP
sidecars
Constants
- XPACKET_END_R
- XPACKET_END_W
- XPACKET_PDATA
- XPACKET_START
Public Class Methods
new(xmp_data_blob, writable: false, xpacked: false)
click to toggle source
# File lib/embed_xmp/xmp.rb, line 20 def initialize(xmp_data_blob, writable: false, xpacked: false) @xmp = xmp_str = xmp_xml_to_str(xmp_data_blob) @xmp = xpack_sidecar(xmp_str, writable: writable) unless xpacked end
Public Instance Methods
to_s()
click to toggle source
Return XMP
sidecar as String
.
# File lib/embed_xmp/xmp.rb, line 27 def to_s xmp_xml_to_str(@xmp) end
xmp_xml_to_str(xmp_data)
click to toggle source
Read XML-formatted XMP
data into a format suitable for embedding.
# File lib/embed_xmp/xmp.rb, line 32 def xmp_xml_to_str(xmp_data) xmp = Nokogiri::XML(xmp_data) do |conf| conf.options = Nokogiri::XML::ParseOptions::NOBLANKS end raise 'XMPIsMalformedXML' unless xmp.errors.empty? xmp.to_xml(indent: 0, encoding: 'utf-8', save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION) end
xpack_sidecar(xmp_data, writable: false)
click to toggle source
Wrap XMP
sidecar data in in an magic XML processing instruction (xpacket). writable
is approperiate for file formats where the XMP
data can be modified in place by staying within the confines of the XPACKET. (E.g. file formats with no chunk checksums.)
# File lib/embed_xmp/xmp.rb, line 48 def xpack_sidecar(xmp_data, writable: false) xpacket_end = writable ? XPACKET_END_W : XPACKET_END_R "#{XPACKET_START}\n#{xmp_data}\n#{xpacket_end}" end