Class Atom::Element
In: lib/atom/yaml.rb
lib/atom/element.rb
Parent: Hash

Methods

[]   []=   to_element   to_s   to_xml  

Attributes

base  [RW]  this element’s xml:base
extensions  [R]  a REXML::Element that shares this element’s extension attributes and child elements

Public Instance methods

get the value of an attribute

[Source]

     # File lib/atom/element.rb, line 115
115:     def [] key
116:       test_key key
117:    
118:       super
119:     end

set the value of an attribute

[Source]

     # File lib/atom/element.rb, line 122
122:     def []= key, value
123:       test_key key
124: 
125:       super
126:     end

convert to a REXML::Element (with no namespace)

[Source]

     # File lib/atom/element.rb, line 147
147:     def to_element 
148:       elem = REXML::Element.new(local_name)
149: 
150:       self.class.elements.each do |name,kind,req|
151:         v = get(name)
152:         next if v.nil?
153: 
154:         if v.respond_to? :to_element
155:           e = v.to_element
156:           e = [ e ] unless e.is_a? Array
157: 
158:           e.each do |bit|
159:             elem << bit
160:           end
161:         else
162:           e = REXML::Element.new(name.to_s, elem).text = get(name)
163:         end
164:       end
165: 
166:       self.class.attrs.each do |name,req|
167:         value = self[name.to_s]
168:         elem.attributes[name.to_s] = value if value
169:       end
170: 
171:       self.extensions.children.each do |element|
172:         elem << element.dup # otherwise they get removed from @extensions
173:       end
174: 
175:       if self.base and not self.base.empty?
176:         elem.attributes["xml:base"] = self.base
177:       end
178: 
179:       elem
180:     end

convert to an XML string

[Source]

     # File lib/atom/element.rb, line 192
192:     def to_s
193:       to_xml.to_s
194:     end

convert to a REXML::Document (properly namespaced)

[Source]

     # File lib/atom/element.rb, line 183
183:     def to_xml
184:       doc = REXML::Document.new
185:       root = to_element
186:       root.add_namespace Atom::NS
187:       doc << root
188:       doc
189:     end

[Validate]