instance method
fold_array_by_name
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.2.3 PrivateSignature
fold_array_by_name(name, array)
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.
Parameters
-
namereq -
arrayreq
Source
# File activesupport/lib/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
Defined in activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb line 598
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in XmlSimple