(Not documented)
# File lib/r4x/e4x.rb, line 52 def new( xmldata, parent=nil ) case xmldata when nil, '' raise ArgumentError when Xml, Symbol, XmlCanonical __new( xmldata, parent ) when REXML::Element, REXML::Text, REXML::Attribute, REXML::Instruction __new( xmldata, parent ) else XmlList.new(xmldata, parent) end end
(Not documented)
# File lib/r4x/e4x.rb, line 66 def initialize( xmldata, parent=nil ) @parent = parent case xmldata when Xml @node = xmldata.__node.dup @class = xmldata.__class.dup @name = xmldata.__node.name.dup when Symbol #@node = REXML::Document.new( "<#{xmldata}></#{xmldata}>" ).root #@node = REXML::Element.new( "<#{xmldata}></#{xmldata}>" ).root @node = REXML::Element.new( xmldata ) @class = :element @name = @node.name when XmlCanonical xmldata = xmldata.to_s @node = REXML::Document.new( xmldata.strip ).root #@node = REXML::Element.new( xmldata.strip ) @class = :element @name = @node.name when REXML::Element @node = xmldata @class = :element @name = @node.name when REXML::Text @node = xmldata @class = :text @name = nil when REXML::Attribute @node = xmldata @class = :attribute @name = xmldata.name when REXML::Instruction @node = xmldata @class = :instruction @name = xmldata.target else raise ArgumentError, "invlaid xml" end @self ||= XmlDelegate.new(self) end
XPath for all elements.
# File lib/r4x/e4x.rb, line 144 def * ; @self.get('*') ; end
Shortcut for add.
# File lib/r4x/e4x.rb, line 139 def <<( n ) @self.add( n ) end
XPath get operator.
# File lib/r4x/e4x.rb, line 150 def []( key ) @self.get( key ) end
XPath put operator.
# File lib/r4x/e4x.rb, line 155 def []=( key, val ) @self.put( key, val ) end
Shortcut for XPath ’@*’, meaning all attributes.
# File lib/r4x/e4x.rb, line 147 def _ ; @self.get('@*') ; end
This is how the delegate accesses the node classification.
# File lib/r4x/e4x.rb, line 125 def __class ; @class ; end
This is how the delegate accesses the node.
# File lib/r4x/e4x.rb, line 122 def __node ; @node ; end
(neccessary?) FIX!!!
# File lib/r4x/e4x.rb, line 134 def each() @node.each_child { |c| yield(c) } end
Here’s where all the fun’s at! It’s more complicated then it looks ;-)
# File lib/r4x/e4x.rb, line 161 def method_missing( sym, *args ) sym = sym.to_s if sym.slice(-1) == '=' self["#{sym.pop}"] = args[0] else self["#{sym}"] end end
This is how to access the underlying Xml object, i.e. via the delegate.
# File lib/r4x/e4x.rb, line 119 def self ; @self ; end
Disabled; run with --debug to generate this.