Class: REXMLUtilityNode

Overview

This is a slighly modified version of the XMLUtilityNode from merb.devjavu.com/projects/merb/ticket/95
(has.sox@gmail.com) It's mainly just adding vowels, as I ht cd wth n
vwls :) This represents the hard part of the work, all I did was change the
underlying parser.

Constructor Details

# File 'lib/crack/xml.rb', line 56definitialize(name,normalized_attributes={})# unnormalize attribute values
attributes=Hash[*normalized_attributes.map{|key,value|[key,unnormalize_xml_entities(value)]}.flatten]@name=name.tr("-","_")# leave the type alone if we don't know what it is
@type=self.class.available_typecasts.include?(attributes["type"])?attributes.delete("type"):attributes["type"]@nil_element=attributes.delete("nil")=="true"@attributes=undasherize_keys(attributes)@children=[]@text=falseend

#to_hash ⇒ Object

# File 'lib/crack/xml.rb', line 78defto_hash# ACG: Added a check here to prevent an exception a type == "file" tag has nodes within it
if@type=="file"and(@children.first.nil?or@children.first.is_a?(String))f=StringIO.new((@children.first||'').unpack('m').first)class<<fattr_accessor:original_filename,:content_typeendf.original_filename=attributes['name']||'untitled'f.content_type=attributes['content_type']||'application/octet-stream'return{name=>f}endif@textt=typecast_value(unnormalize_xml_entities(inner_html))ift.is_a?(String)t=REXMLUtiliyNodeString.new(t)t.attributes=attributesendreturn{name=>t}else#change repeating groups into an array
groups=@children.inject({}){|s,e|(s[e.name]||=[])<<e;s}out=nilif@type=="array"out=[]groups.eachdo|k,v|ifv.size==1out<<v.first.to_hash.entries.first.lastelseout<<v.map{|e|e.to_hash[k]}endendout=out.flattenelse# If Hash
out={}groups.eachdo|k,v|ifv.size==1out.merge!(v.first)elseout.merge!(k=>v.map{|e|e.to_hash[k]})endendout.merge!attributesunlessattributes.empty?out=out.empty??nil:outendif@type&&out.nil?{name=>typecast_value(out)}else{name=>out}endendend