class NXML::Element
Public Class Methods
new(name, &block)
click to toggle source
# File lib/nxml.rb, line 61 def initialize(name, &block) NXML::check_name name @name = name @attributes = {} @children = [] instance_eval &block if block_given? end
Public Instance Methods
a(name, value)
click to toggle source
# File lib/nxml.rb, line 117 def a(name, value) attribute name, value end
attribute(name, value)
click to toggle source
# File lib/nxml.rb, line 102 def attribute(name, value) NXML::check_name name r = NXML::escape_attr_value value @attributes[name] = r r end
attribute_raw(name, value)
click to toggle source
# File lib/nxml.rb, line 109 def attribute_raw(name, value) XML::check_name name r = NXML::escape_attr_raw value @attributes[name] = r r end
cdata(text)
click to toggle source
# File lib/nxml.rb, line 96 def cdata(text) r = CDATA.new(text) @children << r r end
method_missing(name, value = nil, *attrs)
click to toggle source
Calls superclass method
# File lib/nxml.rb, line 71 def method_missing(name, value = nil, *attrs) if name[-1] == '=' name = name[0..-2] if value.nil? @attributes[name] else attribute name, value end else super name, value, *attrs end end
tag(name, &block)
click to toggle source
# File lib/nxml.rb, line 84 def tag(name, &block) r = Element.new(name, &block) @children << r r end
text(text)
click to toggle source
# File lib/nxml.rb, line 90 def text(text) r = Text.new(text) @children << r r end
to_str()
click to toggle source
# File lib/nxml.rb, line 121 def to_str ret = "<#{@name}" if not @attributes.empty? for k,v in @attributes ret += " #{k}=\"#{v}\"" end end if @children.empty? ret += "/>" else ret += ">#{@children.join}</#{@name}>" end ret end