Module: Ayril::XMLElement::ElementAttributeManipulation

Included in:
Ayril::XMLElement
Defined in:
lib/ayril/xml_element/element_attribute_manipulation.rb

Instance Method Summary collapse

Instance Method Details

#attributeObject Also known as: attr



24
25
26
# File 'lib/ayril/xml_element/element_attribute_manipulation.rb', line 24

def attribute
  @attributes.nil? ? (@attributes = XMLElement::XMLAttributeHash.new self) : @attributes
end

#attribute=(hash) ⇒ Object Also known as: attr=, set



29
# File 'lib/ayril/xml_element/element_attribute_manipulation.rb', line 29

def attribute=(hash); self.setAttributesAsDictionary hash end

#has_attribute?(k) ⇒ Boolean

Returns:

  • (Boolean)


57
# File 'lib/ayril/xml_element/element_attribute_manipulation.rb', line 57

def has_attribute?(k); not self.attributeForName(k.to_s).nil? end

#read_attribute(k) ⇒ Object Also known as: get_attribute, []



33
# File 'lib/ayril/xml_element/element_attribute_manipulation.rb', line 33

def read_attribute(k); self.attributeForName(k.to_s).maybe(:stringValue) end

#remove_attribute(a) ⇒ Object Also known as: delete_attribute



54
# File 'lib/ayril/xml_element/element_attribute_manipulation.rb', line 54

def remove_attribute(a) self.removeAttributeForName(a.to_s); self.sync end

#write_attribute(k, v = nil) ⇒ Object Also known as: add_attribute, set_attribute, []=



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ayril/xml_element/element_attribute_manipulation.rb', line 37

def write_attribute(k, v=nil)
  if v.nil? and k.kind_of? Hash
    k.each { |a, b| self.write_attribute a.to_s, b } unless k.empty?
    return self
  end
  attr = self.attributeForName(k)
  if attr.nil?
    self.addAttribute XMLNode.attributeWithName(k.to_s, stringValue: v)
  else
    attr.stringValue = v
  end
  self
end