Class: XmlList
- Inherits:
-
Object
- Object
- XmlList
- Defined in:
- lib/r4x/e4x.rb,
lib/r4x/xmllist_delegate.rb
Overview
XmlList
Defined Under Namespace
Classes: XmlListDelegate
Class Method Summary collapse
Instance Method Summary collapse
-
#* ⇒ Object
XPath for all elements.
-
#<<(n) ⇒ Object
Shortcut for add.
- #[](v) ⇒ Object
- #[]=(prop, v) ⇒ Object
-
#_ ⇒ Object
Shortcut for XPath ‘@*’, meaning all attributes.
-
#__class ⇒ Object
This is how the delegate accesses the node classification.
-
#__list ⇒ Object
This is how the delegate accesses the node.
-
#__target_object ⇒ Object
This is how the delegate accesses the node classification.
- #__target_object=(to) ⇒ Object
-
#__target_property ⇒ Object
This is how the delegate accesses the node classification.
- #__target_property=(tp) ⇒ Object
-
#each(&blk) ⇒ Object
each.
-
#initialize(xd = [], to = nil, tp = nil) ⇒ XmlList
constructor
A new instance of XmlList.
- #method_missing(sym, *args) ⇒ Object
-
#self ⇒ Object
This is how to access the underlying Xml object, i.e.
-
#to_i ⇒ Object
?.
-
#to_s ⇒ Object
Important for this to work in string interpolation.
Constructor Details
#initialize(xd = [], to = nil, tp = nil) ⇒ XmlList
Returns a new instance of XmlList.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/r4x/e4x.rb', line 189 def initialize( xd=[], to=nil, tp=nil ) @self = XmlListDelegate.new(self) case xd when [] @list = [] @target_object = to @target_property = tp when Xml @list = [xd] @target_object = xd.self.parent @target_property = xd.self.name else xd = REXML::Document.new(%{<_>#{xd}</_>}).root a = []; xd.each{ |n| a << Xml.new(n) } @list = a @target_object = nil @target_property = nil end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'lib/r4x/e4x.rb', line 255 def method_missing( sym, *args ) sym = sym.to_s p sym if (args.size > 0) self[0].send( sym, args ) else self[0].send( sym ) end end |
Class Method Details
.__new ⇒ Object
178 |
# File 'lib/r4x/e4x.rb', line 178 alias_method( :__new, :new ) |
.new(xd = [], to = nil, tp = nil) ⇒ Object
179 180 181 182 183 184 185 186 |
# File 'lib/r4x/e4x.rb', line 179 def new( xd=[], to=nil, tp=nil ) case xd when XmlList xd else __new( xd, to, tp ) end end |
Instance Method Details
#* ⇒ Object
XPath for all elements.
241 |
# File 'lib/r4x/e4x.rb', line 241 def * ; @self.get('*') ; end |
#<<(n) ⇒ Object
Shortcut for add.
236 237 238 |
# File 'lib/r4x/e4x.rb', line 236 def <<( n ) @self.add( n ) end |
#[](v) ⇒ Object
246 247 248 |
# File 'lib/r4x/e4x.rb', line 246 def []( v ) @self.get( v ) end |
#[]=(prop, v) ⇒ Object
250 251 252 |
# File 'lib/r4x/e4x.rb', line 250 def []=( prop, v ) @self.put( prop , v ) end |
#_ ⇒ Object
Shortcut for XPath ‘@*’, meaning all attributes.
244 |
# File 'lib/r4x/e4x.rb', line 244 def _ ; @self.get('@*') ; end |
#__class ⇒ Object
This is how the delegate accesses the node classification.
216 |
# File 'lib/r4x/e4x.rb', line 216 def __class ; :xmllist ; end |
#__list ⇒ Object
This is how the delegate accesses the node.
213 |
# File 'lib/r4x/e4x.rb', line 213 def __list ; @list ; end |
#__target_object ⇒ Object
This is how the delegate accesses the node classification.
219 |
# File 'lib/r4x/e4x.rb', line 219 def __target_object ; @target_object ; end |
#__target_object=(to) ⇒ Object
220 |
# File 'lib/r4x/e4x.rb', line 220 def __target_object=(to) ; @target_object = to ; end |
#__target_property ⇒ Object
This is how the delegate accesses the node classification.
223 |
# File 'lib/r4x/e4x.rb', line 223 def __target_property ; @target_property ; end |
#__target_property=(tp) ⇒ Object
224 |
# File 'lib/r4x/e4x.rb', line 224 def __target_property=(tp) ; @target_property = tp ; end |
#each(&blk) ⇒ Object
each
233 |
# File 'lib/r4x/e4x.rb', line 233 def each(&blk) ; @list.each(&blk) ; end |
#self ⇒ Object
This is how to access the underlying Xml object, i.e. via the delegate.
210 |
# File 'lib/r4x/e4x.rb', line 210 def self ; @self ; end |
#to_i ⇒ Object
?
230 |
# File 'lib/r4x/e4x.rb', line 230 def to_i() @list.to_s.to_i; end |
#to_s ⇒ Object
Important for this to work in string interpolation.
227 |
# File 'lib/r4x/e4x.rb', line 227 def to_s() @list.to_s ; end |