Class: REXML::Object::ClassifiedElementList

Inherits:
ReflectiveElementList show all
Defined in:
lib/voruby/misc/rexml_ext.rb

Instance Attribute Summary collapse

Attributes inherited from ReflectiveElementList

#parent, #xpath

Instance Method Summary collapse

Methods inherited from ReflectiveElementList

#delete_at, #size

Constructor Details

#initialize(klass, parent, *xpath) ⇒ ClassifiedElementList

Returns a new instance of ClassifiedElementList.



73
74
75
76
# File 'lib/voruby/misc/rexml_ext.rb', line 73

def initialize(klass, parent, *xpath)
  @klass = klass
  super(parent, *xpath)
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

Instance Method Details

#<<(obj) ⇒ Object



87
88
89
# File 'lib/voruby/misc/rexml_ext.rb', line 87

def <<(obj)
  super(obj.node)
end

#==(ary) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/voruby/misc/rexml_ext.rb', line 116

def ==(ary)
  return false if self.size != ary.size
  
  self.each_with_index do |item, i|
    return false if item != ary[i]
  end
  
  return true
end

#[](i) ⇒ Object



78
79
80
# File 'lib/voruby/misc/rexml_ext.rb', line 78

def [](i)
  self.klass.new(super(i))
end

#[]=(i, obj) ⇒ Object



82
83
84
85
# File 'lib/voruby/misc/rexml_ext.rb', line 82

def []=(i, obj)
  el = self[i]
  el ? el.node.replace_with(obj.node) : self<<(obj.node)
end

#clearObject



112
113
114
# File 'lib/voruby/misc/rexml_ext.rb', line 112

def clear
  self.each { |el| el.node.remove }
end

#eachObject



108
109
110
# File 'lib/voruby/misc/rexml_ext.rb', line 108

def each
  XPath.each(self.parent, *self.xpath) { |el| yield self.klass.new(el) }
end

#firstObject



95
96
97
# File 'lib/voruby/misc/rexml_ext.rb', line 95

def first
  self.klass.new(super())
end

#lastObject



91
92
93
# File 'lib/voruby/misc/rexml_ext.rb', line 91

def last
  self.klass.new(super())
end

#replace(ary) ⇒ Object



103
104
105
106
# File 'lib/voruby/misc/rexml_ext.rb', line 103

def replace(ary)
  self.clear
  ary.each { |obj| self<<(obj) }
end

#to_aObject



99
100
101
# File 'lib/voruby/misc/rexml_ext.rb', line 99

def to_a
  super().collect{ |el| self.klass.new(el) }
end