Class: Ayril::XMLElement::XMLAttributeHash
- Defined in:
- lib/ayril/xml_element/xml_attribute_hash.rb
Instance Method Summary collapse
- #_delete_if(&blk) ⇒ Object
- #clear ⇒ Object
- #delete(k) ⇒ Object (also: #remove, #-)
- #delete_if(&blk) ⇒ Object
- #fetch(k) ⇒ Object (also: #get, #[])
- #has_key?(k) ⇒ Boolean (also: #has?, #include?, #key?, #member?)
-
#initialize(element) ⇒ XMLAttributeHash
constructor
A new instance of XMLAttributeHash.
- #inspect ⇒ Object
- #merge!(hash) ⇒ Object (also: #update!, #+)
- #reject!(&blk) ⇒ Object
- #replace(hash) ⇒ Object
- #store(k, v) ⇒ Object (also: #set, #[]=)
- #sync ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(element) ⇒ XMLAttributeHash
Returns a new instance of XMLAttributeHash.
4 5 6 7 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 4 def initialize(element) @element = element self.sync end |
Instance Method Details
#_delete_if(&blk) ⇒ Object
41 |
# 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 ⇒ Object
50 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 50 def clear; self.replace {} end |
#delete(k) ⇒ Object Also known as: remove, -
37 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 37 def delete(k); @element.removeAttributeForName k; super k end |
#delete_if(&blk) ⇒ Object
42 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 42 def delete_if(&blk); self._delete_if &blk; self end |
#fetch(k) ⇒ Object Also known as: get, []
27 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 27 def fetch(k); @element.attributeForName(k).maybe :stringValue end |
#has_key?(k) ⇒ Boolean Also known as: has?, include?, key?, member?
31 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 31 def has_key?(k); not @element.attributeForName(k).nil? end |
#inspect ⇒ Object
57 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 57 def inspect; "#<#{self.class} #{self.to_s}>" end |
#merge!(hash) ⇒ Object Also known as: update!, +
52 |
# 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) ⇒ Object
44 45 46 47 |
# 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) ⇒ Object
49 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 49 def replace(hash); @element.setAttributesAsDictionary hash; super hash end |
#store(k, v) ⇒ Object Also known as: set, []=
15 16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
9 10 11 12 13 |
# 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 ⇒ Object
56 |
# File 'lib/ayril/xml_element/xml_attribute_hash.rb', line 56 def to_s; self.map { |k, v| "#{k}=\"#{v}\"" }.join ' ' end |