Class: XML::XXPath::Accessors::Attribute

Inherits:
Object
  • Object
show all
Includes:
UnspecifiednessSupport, XML::XXPathMethods
Defined in:
lib/xml/rexml_ext.rb,
lib/xml/xxpath_methods.rb

Overview

attribute node, more or less call-compatible with REXML’s Element. REXML’s Attribute class doesn’t provide this…

The all/first calls return instances of this class if they matched an attribute node.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UnspecifiednessSupport

append_features, #unspecified=, #unspecified?

Methods included from XML::XXPathMethods

#all_xpath, #create_new_xpath, #each_xpath, #first_xpath, #to_xxpath

Constructor Details

#initialize(parent, name) ⇒ Attribute

Returns a new instance of Attribute.



74
75
76
# File 'lib/xml/rexml_ext.rb', line 74

def initialize(parent,name)
  @parent,@name = parent,name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



71
72
73
# File 'lib/xml/rexml_ext.rb', line 71

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



71
72
73
# File 'lib/xml/rexml_ext.rb', line 71

def parent
  @parent
end

Class Method Details

.new(parent, name, create) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/xml/rexml_ext.rb', line 78

def self.new(parent,name,create)
  if parent.attributes[name]
    super(parent,name)
  else
    if create
      parent.attributes[name] = "[unset]"
      super(parent,name)
    else
      nil
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



100
101
102
# File 'lib/xml/rexml_ext.rb', line 100

def ==(other)
  other.kind_of?(Attribute) and other.parent==parent and other.name==name
end

#textObject

the value of the attribute.



92
93
94
# File 'lib/xml/rexml_ext.rb', line 92

def text
  parent.attributes[@name]
end

#text=(x) ⇒ Object



96
97
98
# File 'lib/xml/rexml_ext.rb', line 96

def text=(x)
  parent.attributes[@name] = x
end