Class: REXML::Object::ReflectiveElementList
- Inherits:
-
Object
- Object
- REXML::Object::ReflectiveElementList
- Includes:
- Enumerable
- Defined in:
- lib/voruby/misc/rexml_ext.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#xpath ⇒ Object
readonly
Returns the value of attribute xpath.
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #[](i) ⇒ Object
- #[]=(i, element) ⇒ Object
- #clear ⇒ Object
- #delete_at(i) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(parent, *xpath) ⇒ ReflectiveElementList
constructor
A new instance of ReflectiveElementList.
- #last ⇒ Object
- #replace(ary) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(parent, *xpath) ⇒ ReflectiveElementList
Returns a new instance of ReflectiveElementList.
11 12 13 14 |
# File 'lib/voruby/misc/rexml_ext.rb', line 11 def initialize(parent, *xpath) @parent = parent @xpath = xpath end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/voruby/misc/rexml_ext.rb', line 9 def parent @parent end |
#xpath ⇒ Object (readonly)
Returns the value of attribute xpath.
9 10 11 |
# File 'lib/voruby/misc/rexml_ext.rb', line 9 def xpath @xpath end |
Instance Method Details
#<<(element) ⇒ Object
26 27 28 29 30 |
# File 'lib/voruby/misc/rexml_ext.rb', line 26 def <<(element) path = "#{self.xpath.first}[last()]" last = XPath.first(self.parent, path, self.xpath.last) last ? last.next_sibling = element : self.parent << element end |
#[](i) ⇒ Object
16 17 18 19 |
# File 'lib/voruby/misc/rexml_ext.rb', line 16 def [](i) path = "#{self.xpath.first}[#{i+1}]" XPath.first(self.parent, path, self.xpath.last) end |
#[]=(i, element) ⇒ Object
21 22 23 24 |
# File 'lib/voruby/misc/rexml_ext.rb', line 21 def []=(i, element) el = self[i] el ? el.replace_with(element) : self<<(element) end |
#clear ⇒ Object
56 57 58 |
# File 'lib/voruby/misc/rexml_ext.rb', line 56 def clear self.each { |el| el.remove } end |
#delete_at(i) ⇒ Object
42 43 44 45 |
# File 'lib/voruby/misc/rexml_ext.rb', line 42 def delete_at(i) path = "#{self.xpath.first}[#{i+1}]" XPath.first(self.parent, path, self.xpath.last).remove end |
#each ⇒ Object
65 66 67 |
# File 'lib/voruby/misc/rexml_ext.rb', line 65 def each XPath.each(self.parent, *self.xpath) { |el| yield el } end |
#first ⇒ Object
37 38 39 40 |
# File 'lib/voruby/misc/rexml_ext.rb', line 37 def first path = "#{self.xpath.first}[1]" XPath.first(self.parent, path, self.xpath.last) end |
#last ⇒ Object
32 33 34 35 |
# File 'lib/voruby/misc/rexml_ext.rb', line 32 def last path = "#{self.xpath.first}[last()]" XPath.first(self.parent, path, self.xpath.last) end |
#replace(ary) ⇒ Object
60 61 62 63 |
# File 'lib/voruby/misc/rexml_ext.rb', line 60 def replace(ary) self.clear ary.each { |el| self<<(el) } end |
#size ⇒ Object
47 48 49 50 |
# File 'lib/voruby/misc/rexml_ext.rb', line 47 def size path = "count(#{self.xpath.first})" XPath.first(self.parent, path, self.xpath.last) end |
#to_a ⇒ Object
52 53 54 |
# File 'lib/voruby/misc/rexml_ext.rb', line 52 def to_a XPath.match(self.parent, *self.xpath) end |