private Method

XmlSimple.fold_array(array)

Folds an Array to a Hash, if possible. Folding happens according to the content of keyattr, which has to be an array.

array:Array to be folded.

Source Code

# File active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 568
def fold_array(array)
  hash = Hash.new
  array.each { |x|
    return array unless x.instance_of?(Hash)
    key_matched = false
    @options['keyattr'].each { |key|
      if x.has_key?(key)
        key_matched = true
        value = x[key]
        return array if value.instance_of?(Hash) || value.instance_of?(Array)
        value = normalise_space(value) if @options['normalisespace'] == 1
        x.delete(key)
        hash[value] = x
        break
      end
    }
    return array unless key_matched
  }
  hash = collapse_content(hash) if @options['collapseagain']
  hash
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.