Class: XML::XXPath::NameAndAttrStep
- Inherits:
-
Step
- Object
- Step
- XML::XXPath::NameAndAttrStep
show all
- Defined in:
- lib/xml/xxpath/steps.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Step
#creator, inherited, #reader
Constructor Details
#initialize(axis, name, attr_name, attr_value) ⇒ NameAndAttrStep
Returns a new instance of NameAndAttrStep.
124
125
126
127
|
# File 'lib/xml/xxpath/steps.rb', line 124
def initialize(axis,name,attr_name,attr_value)
super(axis)
@name,@attr_name,@attr_value = name,attr_name,attr_value
end
|
Class Method Details
.compile(axis, string) ⇒ Object
119
120
121
122
|
# File 'lib/xml/xxpath/steps.rb', line 119
def self.compile axis, string
/^(.*?)\[@(.*?)='(.*?)'\]$/ === string or return nil
self.new axis,$1,$2,$3
end
|
Instance Method Details
#create_on(node, create_new) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/xml/xxpath/steps.rb', line 133
def create_on(node,create_new)
if create_new
newnode = node.elements.add(@name)
else
newnode = node.elements.select{|elt| elt.name==@name and not(elt.attributes[@attr_name])}[0]
if not(newnode)
newnode = node.elements.add(@name)
end
end
newnode.attributes[@attr_name]=@attr_value
newnode
end
|
#matches?(node) ⇒ Boolean
129
130
131
|
# File 'lib/xml/xxpath/steps.rb', line 129
def matches? node
node.is_a?(REXML::Element) and node.name==@name and node.attributes[@attr_name]==@attr_value
end
|