Class RSS::XML::Element
In: lib/rss/xml.rb
Parent: Object

Methods

<<   ==   []   []=   each   full_name   new   to_s  

Included Modules

Enumerable

Attributes

attributes  [R] 
children  [R] 
name  [R] 
prefix  [R] 
uri  [R] 

Public Class methods

[Source]

    # File lib/rss/xml.rb, line 9
 9:       def initialize(name, prefix=nil, uri=nil, attributes={}, children=[])
10:         @name = name
11:         @prefix = prefix
12:         @uri = uri
13:         @attributes = attributes
14:         if children.is_a?(String) or !children.respond_to?(:each)
15:           @children = [children]
16:         else
17:           @children = children
18:         end
19:       end

Public Instance methods

[Source]

    # File lib/rss/xml.rb, line 29
29:       def <<(child)
30:         @children << child
31:       end

[Source]

    # File lib/rss/xml.rb, line 37
37:       def ==(other)
38:         other.kind_of?(self.class) and
39:           @name == other.name and
40:           @uri == other.uri and
41:           @attributes == other.attributes and
42:           @children == other.children
43:       end

[Source]

    # File lib/rss/xml.rb, line 21
21:       def [](name)
22:         @attributes[name]
23:       end

[Source]

    # File lib/rss/xml.rb, line 25
25:       def []=(name, value)
26:         @attributes[name] = value
27:       end

[Source]

    # File lib/rss/xml.rb, line 33
33:       def each(&block)
34:         @children.each(&block)
35:       end

[Source]

    # File lib/rss/xml.rb, line 62
62:       def full_name
63:         if @prefix
64:           "#{@prefix}:#{@name}"
65:         else
66:           @name
67:         end
68:       end

[Source]

    # File lib/rss/xml.rb, line 45
45:       def to_s
46:         rv = "<#{full_name}"
47:         attributes.each do |key, value|
48:           rv << " #{Utils.html_escape(key)}=\"#{Utils.html_escape(value)}\""
49:         end
50:         if children.empty?
51:           rv << "/>"
52:         else
53:           rv << ">"
54:           children.each do |child|
55:             rv << child.to_s
56:           end
57:           rv << "</#{full_name}>"
58:         end
59:         rv
60:       end

[Validate]