Class: Resync::XML::HashCodesNode
- Inherits:
-
XML::Mapping::SingleAttributeNode
- Object
- XML::Mapping::SingleAttributeNode
- Resync::XML::HashCodesNode
- Defined in:
- lib/resync/xml.rb
Overview
Maps the whitespace-separated list of hash codes in a <rs:ln> or <rs:md> tag to a hash of digest values keyed by hash algorithm. (See Descriptor#hashes.)
Instance Method Summary collapse
-
#extract_attr_value(xml) ⇒ Object
Implements ::XML::Mapping::SingleAttributeNode#extract_attr_value.
-
#initialize(*args) ⇒ HashCodesNode
constructor
A new instance of HashCodesNode.
-
#set_attr_value(xml, value) ⇒ Object
Implements ::XML::Mapping::SingleAttributeNode#set_attr_value.
Constructor Details
#initialize(*args) ⇒ HashCodesNode
Returns a new instance of HashCodesNode.
191 192 193 194 195 |
# File 'lib/resync/xml.rb', line 191 def initialize(*args) path, *args = super(*args) @path = ::XML::XXPath.new(path) args end |
Instance Method Details
#extract_attr_value(xml) ⇒ Object
Implements ::XML::Mapping::SingleAttributeNode#extract_attr_value.
198 199 200 201 202 203 |
# File 'lib/resync/xml.rb', line 198 def extract_attr_value(xml) hashes = default_when_xpath_err { @path.first(xml).text } return {} unless hashes return hashes if hashes.is_a?(Hash) hashes.split(/[[:space:]]+/).map { |hash| hash.split(':') }.to_h end |
#set_attr_value(xml, value) ⇒ Object
Implements ::XML::Mapping::SingleAttributeNode#set_attr_value.
206 207 208 209 210 |
# File 'lib/resync/xml.rb', line 206 def set_attr_value(xml, value) return if value.empty? hash_str = value.map { |k, v| "#{k}:#{v}" }.join(' ') @path.first(xml, ensure_created: true).text = hash_str end |