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

+(hash)
Alias for: merge!
-(k)
Alias for: delete
[](k)
Alias for: fetch
[]=(k, v)
Alias for: store
_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
Also aliased as: remove, -
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
Also aliased as: get, []
get(k)
Alias for: fetch
has?(k)
Alias for: has_key?
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
Also aliased as: has?, include?, key?, member?
include?(k)
Alias for: has_key?
inspect() click to toggle source
# File lib/ayril/xml_element/xml_attribute_hash.rb, line 57
def inspect; "#<#{self.class} #{self.to_s}>" end
key?(k)
Alias for: has_key?
member?(k)
Alias for: has_key?
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
Also aliased as: update!, +
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
remove(k)
Alias for: delete
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
set(k, v)
Alias for: store
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
Also aliased as: set, []=
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
update!(hash)
Alias for: merge!