Folds an Array to a Hash, if possible. Folding happens according to the content of keyattr, which has to be a Hash.
| name: | Name of the attribute to be folded upon. |
| array: | Array to be folded. |
Source Code
# File active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 598 def fold_array_by_name(name, array) return array unless @options['keyattr'].has_key?(name) key, flag = @options['keyattr'][name] hash = Hash.new array.each { |x| if x.instance_of?(Hash) && x.has_key?(key) value = x[key] return array if value.instance_of?(Hash) || value.instance_of?(Array) value = normalise_space(value) if @options['normalisespace'] == 1 hash[value] = x hash[value]["-#{key}"] = hash[value][key] if flag == '-' hash[value].delete(key) unless flag == '+' else $stderr.puts("Warning: <#{name}> element has no '#{key}' attribute.") return array end } hash = collapse_content(hash) if @options['collapseagain'] hash end
<code/>and<pre/>for code samples.