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. 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) ⇒ Attr
constructor
A new instance of Attr.
- #inspect ⇒ Object
- #namespace ⇒ Object
- #remove ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
-
#to_xml ⇒ Object
Serialized attribute form: name="value" with the five XML special characters escaped in the value.
Constructor Details
#initialize(name, value, element) ⇒ Attr
Returns a new instance of Attr.
10 11 12 13 14 |
# File 'lib/leptris/xml/attr.rb', line 10 def initialize(name, value, element) @name = name @value = value @element = element end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
8 9 10 |
# File 'lib/leptris/xml/attr.rb', line 8 def element @element end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/leptris/xml/attr.rb', line 8 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/leptris/xml/attr.rb', line 8 def value @value end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 46 47 |
# File 'lib/leptris/xml/attr.rb', line 43 def ==(other) other.is_a?(Leptris::XML::Attr) && @name == other.name && @value == other.value && @element == other.element end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/leptris/xml/attr.rb', line 49 def inspect "#<#{self.class.name} name=#{@name.inspect} value=#{@value.inspect}>" end |
#namespace ⇒ Object
21 22 23 |
# File 'lib/leptris/xml/attr.rb', line 21 def namespace nil # upstream gap: per-attribute namespace not exposed end |
#remove ⇒ Object
25 26 27 |
# File 'lib/leptris/xml/attr.rb', line 25 def remove @element.remove_attribute(@name) end |
#to_s ⇒ Object
29 |
# File 'lib/leptris/xml/attr.rb', line 29 def to_s; @value; end |
#to_str ⇒ Object
30 |
# File 'lib/leptris/xml/attr.rb', line 30 def to_str; @value; end |
#to_xml ⇒ Object
Serialized attribute form: name="value" with the five XML special characters escaped in the value.
34 35 36 37 38 39 40 41 |
# File 'lib/leptris/xml/attr.rb', line 34 def to_xml escaped = @value.to_s.gsub("&", "&") .gsub("<", "<") .gsub(">", ">") .gsub('"', """) .gsub("'", "'") "#{@name}=\"#{escaped}\"" end |