class Ayril::XMLElement::XMLAttributeHash
Public Class Methods
new(element)
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 4 def initialize(element) @element = element self.sync end
Public Instance Methods
_delete_if(&blk)
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 41 def _delete_if(&blk); self.each { |k, v| self.delete k if blk.call k, v } end
clear()
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 50 def clear; self.replace {} end
delete(k)
click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 37 def delete(k); @element.removeAttributeForName k; super k end
delete_if(&blk)
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 42 def delete_if(&blk); self._delete_if &blk; self end
fetch(k)
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 27 def fetch(k); @element.attributeForName(k).maybe :stringValue end
has_key?(k)
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 31 def has_key?(k); not @element.attributeForName(k).nil? end
inspect()
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 57 def inspect; "#<#{self.class} #{self.to_s}>" end
merge!(hash)
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 52 def merge!(hash); hash.each { |k, v| self[k] = v }; self end
reject!(&blk)
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 44 def reject!(&blk) old = self.dup; self._delete_if &blk (self == old) ? nil : self end
replace(hash)
click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 49 def replace(hash); @element.setAttributesAsDictionary hash; super hash end
store(k, v)
click to toggle source
Calls superclass method
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 15 def store(k, v) attr = @element.attributeForName k if not attr.nil? attr.stringValue = v else @element.addAttribute XMLNode.attributeWithName(k, stringValue: v) end super k, v end
sync()
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 9 def sync cache = {} @element.attributes.each { |a| cache[a.name] = a.stringValue } if not @element.attributes.nil? self.delete_if { true }.merge! cache end
to_s()
click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 56 def to_s; self.map { |k, v| "#{k}=\"#{v}\"" }.join ' ' end