Class: Leptris::XML::Attr
- Inherits:
-
Object
- Object
- Leptris::XML::Attr
- Defined in:
- lib/leptris/xml/attr.rb
Overview
Lightweight attribute wrapper: a (name, value, parent_element) triple materialized from the attribute-iteration face, carrying the C attribute handle for the per-attribute namespace accessors. Mutation goes through the parent element via #[].
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, value, element, c_handle: nil) ⇒ Attr
constructor
c_handle is the C LeptrisAttribute pointer from the owning element's iteration face — document-owned and borrowed.
- #inspect ⇒ Object
- #namespace ⇒ Object
-
#namespace_uri ⇒ Object
The attribute's namespace URI, resolved through the OWNING element's in-scope declarations at read time (libleptris 1.8.0).
-
#prefix ⇒ Object
The prefix as written in the qualified name (bytes before the colon), nil for a no-namespace attribute.
- #remove ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(name, value, element, c_handle: nil) ⇒ Attr
c_handle is the C LeptrisAttribute pointer from the owning element's iteration face — document-owned and borrowed. Absent only when an Attr is constructed by hand.
14 15 16 17 18 19 |
# File 'lib/leptris/xml/attr.rb', line 14 def initialize(name, value, element, c_handle: nil) @name = name @value = value @element = element @c_handle = c_handle end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
9 10 11 |
# File 'lib/leptris/xml/attr.rb', line 9 def element @element end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/leptris/xml/attr.rb', line 9 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/leptris/xml/attr.rb', line 9 def value @value end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 70 71 |
# File 'lib/leptris/xml/attr.rb', line 67 def ==(other) other.is_a?(Leptris::XML::Attr) && @name == other.name && @value == other.value && @element == other.element end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/leptris/xml/attr.rb', line 73 def inspect "#<#{self.class.name} name=#{@name.inspect} value=#{@value.inspect}>" end |
#namespace ⇒ Object
44 45 46 |
# File 'lib/leptris/xml/attr.rb', line 44 def namespace namespace_uri end |
#namespace_uri ⇒ Object
The attribute's namespace URI, resolved through the OWNING element's in-scope declarations at read time (libleptris 1.8.0). nil for a no-namespace attribute or an undeclared prefix; xml is prebound to http://www.w3.org/XML/1998/namespace.
39 40 41 42 |
# File 'lib/leptris/xml/attr.rb', line 39 def namespace_uri return nil if @c_handle.nil? Leptris::XML::FFI.leptris_attribute_namespace_uri(@c_handle) end |
#prefix ⇒ Object
The prefix as written in the qualified name (bytes before the colon), nil for a no-namespace attribute. Name-derived and immutable — the same semantics as leptris_attribute_prefix, so no declaration lookup is involved.
30 31 32 33 |
# File 'lib/leptris/xml/attr.rb', line 30 def prefix i = @name.index(":") i ? @name[0, i] : nil end |
#remove ⇒ Object
48 49 50 |
# File 'lib/leptris/xml/attr.rb', line 48 def remove @element.remove_attribute(@name) end |
#to_s ⇒ Object
52 |
# File 'lib/leptris/xml/attr.rb', line 52 def to_s; @value; end |
#to_str ⇒ Object
53 |
# File 'lib/leptris/xml/attr.rb', line 53 def to_str; @value; end |
#to_xml ⇒ Object
63 64 65 |
# File 'lib/leptris/xml/attr.rb', line 63 def to_xml "#{@name}=\"#{@value.to_s.gsub(/[&<>"']/, ESCAPE_TABLE)}\"" end |