Class: XmlList

Inherits:
Object
  • Object
show all
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

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

.__newObject



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

#__classObject

This is how the delegate accesses the node classification.



216
# File 'lib/r4x/e4x.rb', line 216

def __class ; :xmllist ; end

#__listObject

This is how the delegate accesses the node.



213
# File 'lib/r4x/e4x.rb', line 213

def __list  ; @list ; end

#__target_objectObject

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_propertyObject

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

#selfObject

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_iObject

?



230
# File 'lib/r4x/e4x.rb', line 230

def to_i() @list.to_s.to_i; end

#to_sObject

Important for this to work in string interpolation.



227
# File 'lib/r4x/e4x.rb', line 227

def to_s() @list.to_s ; end