Class: Taurus::XML::Attr

Inherits:
Object
  • Object
show all
Defined in:
lib/taurus/xml/attr.rb

Overview

Lightweight attribute wrapper. libtaurus v0.4.4 doesn't expose per-attribute pointers (no TaurusAttribute accessors in the public API), so an Attr is a (name, value, parent_element) triple. Mutation goes through the parent element via #[]. Once upstream adds attribute-level accessors, this can become a pointer-backed wrapper.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, element) ⇒ Attr

Returns a new instance of Attr.



12
13
14
15
16
# File 'lib/taurus/xml/attr.rb', line 12

def initialize(name, value, element)
  @name = name
  @value = value
  @element = element
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



10
11
12
# File 'lib/taurus/xml/attr.rb', line 10

def element
  @element
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/taurus/xml/attr.rb', line 10

def name
  @name
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/taurus/xml/attr.rb', line 10

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
38
# File 'lib/taurus/xml/attr.rb', line 34

def ==(other)
  other.is_a?(Taurus::XML::Attr) &&
    @name == other.name && @value == other.value &&
    @element == other.element
end

#inspectObject



40
41
42
# File 'lib/taurus/xml/attr.rb', line 40

def inspect
  "#<#{self.class.name} name=#{@name.inspect} value=#{@value.inspect}>"
end

#namespaceObject



23
24
25
# File 'lib/taurus/xml/attr.rb', line 23

def namespace
  nil  # upstream gap: per-attribute namespace not exposed
end

#removeObject



27
28
29
# File 'lib/taurus/xml/attr.rb', line 27

def remove
  @element.remove_attribute(@name)
end

#to_sObject



31
# File 'lib/taurus/xml/attr.rb', line 31

def to_s; @value; end

#to_strObject



32
# File 'lib/taurus/xml/attr.rb', line 32

def to_str; @value; end