class Oga::XML::Attribute
Class for storing information about a single XML
attribute.
Constants
- DEFAULT_NAMESPACE
The default namespace available to all attributes. This namespace can not be modified.
@return [Oga::XML::Namespace]
Attributes
The element this attribute belongs to. @return [Oga::XML::Element]
The name of the attribute. @return [String]
@return [String]
The element this attribute belongs to. @return [Oga::XML::Element]
Public Class Methods
@param [Hash] options
@option options [String] :name @option options [String] :namespace_name @option options [String] :value @option options [Oga::XML::Element] :element
# File lib/oga/xml/attribute.rb, line 36 def initialize(options = {}) @name = options[:name] @value = options[:value] @element = options[:element] @decoded = false @namespace = nil @namespace_name = options[:namespace_name] end
Public Instance Methods
@see [Oga::XML::Node#each_ancestor]
# File lib/oga/xml/attribute.rb, line 102 def each_ancestor return to_enum(:each_ancestor) unless block_given? return unless element yield element element.each_ancestor { |ancestor| yield ancestor } end
@return [String]
# File lib/oga/xml/attribute.rb, line 87 def inspect segments = [] [:name, :namespace, :value].each do |attr| value = send(attr) if value segments << "#{attr}: #{value.inspect}" end end "Attribute(#{segments.join(' ')})" end
Returns the {Oga::XML::Namespace} instance for the current namespace name.
@return [Oga::XML::Namespace]
# File lib/oga/xml/attribute.rb, line 49 def namespace unless @namespace if namespace_name == DEFAULT_NAMESPACE.name @namespace = DEFAULT_NAMESPACE else @namespace = element.available_namespaces[namespace_name] end end @namespace end
@return [String]
# File lib/oga/xml/attribute.rb, line 80 def text value.to_s end
Returns the value of the attribute or nil if no explicit value was set.
@return [String|NilClass]
# File lib/oga/xml/attribute.rb, line 70 def value if !@decoded and @value @value = EntityDecoder.try_decode(@value, html?) @decoded = true end @value end
@param [String] value
# File lib/oga/xml/attribute.rb, line 62 def value=(value) @value = value @decoded = false end
Private Instance Methods
@return [TrueClass|FalseClass]
# File lib/oga/xml/attribute.rb, line 115 def html? !!@element && @element.html? end