Class: AIXM::PayloadHash::Mid
Overview
Insert OFMX-compliant payload hashes as mid attributes into an XML document.
Keep in mind: If you pass a Nokogiri::XML::Document, the mid attributes are added into this document. In order to leave the original document untouched, you have to ‘dup` it.
Instance Method Summary collapse
-
#check_mid ⇒ Array<String>
Check mid attributes on all *Uid elements.
-
#initialize(document) ⇒ Mid
constructor
A new instance of Mid.
-
#insert_mid ⇒ self
Insert or update mid attributes on all *Uid elements.
-
#to_xml ⇒ String
XML document as XML string.
Constructor Details
#initialize(document) ⇒ Mid
Returns a new instance of Mid.
75 76 77 78 79 80 81 |
# File 'lib/aixm/payload_hash.rb', line 75 def initialize(document) @document = case document when Nokogiri::XML::Document then document when String then Nokogiri::XML(document) else fail ArgumentError end end |
Instance Method Details
#check_mid ⇒ Array<String>
Check mid attributes on all *Uid elements
96 97 98 99 100 101 102 |
# File 'lib/aixm/payload_hash.rb', line 96 def check_mid uid_elements.each_with_object([]) do |element, errors| unless element['mid'] == (uuid = AIXM::PayloadHash.new(element).to_uuid) errors << "#{element.line}: ERROR: Element '#{element.name}': mid should be #{uuid}" end end end |
#insert_mid ⇒ self
Insert or update mid attributes on all *Uid elements
86 87 88 89 90 91 |
# File 'lib/aixm/payload_hash.rb', line 86 def insert_mid uid_elements.each do |element| element['mid'] = AIXM::PayloadHash.new(element).to_uuid end self end |
#to_xml ⇒ String
Returns XML document as XML string.
105 106 107 |
# File 'lib/aixm/payload_hash.rb', line 105 def to_xml @document.to_xml end |