Class: XmlFu::Hash
- Inherits:
-
Object
- Object
- XmlFu::Hash
- Defined in:
- lib/xml-fu/hash.rb
Overview
By definition, a hash is an UNORDERED list of key/value pairs There's no sense in trying to order the keys. If order is of concern, use Array.to_xml
Class Method Summary (collapse)
-
+ (Object) filter(hash)
Class method to filter out attributes and content from a given hash.
-
+ (Object) to_xml(hash, options = {})
Convert Hash to XML String.
Class Method Details
+ (Object) filter(hash)
Class method to filter out attributes and content from a given hash
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/xml-fu/hash.rb', line 22 def self.filter(hash) attribs = {} content = hash.dup content.keys.select{|k| k =~ /^@/ }.each do |k| attribs[k[1..-1]] = content.delete(k) end # Use _content value if defined content = content.delete("=") || content return [content, attribs] end |
+ (Object) to_xml(hash, options = {})
Convert Hash to XML String
13 14 15 16 17 |
# File 'lib/xml-fu/hash.rb', line 13 def self.to_xml(hash, ={}) each_with_xml hash, do |xml, name, value, attributes| xml << Node.new(name, value, attributes).to_xml end end |