244: def pathkvlist(key, arr_of_hashes, key_name, value_name, mappings)
245: raise ArgumentError, "expected a key that is a String" unless key.is_a? String
246: raise ArgumentError, "expected a arr_of_hashes that is an Array" unless arr_of_hashes.is_a? Array
247: arr_of_hashes.each{|h| raise ArgumentError, "expected each element of arr_of_hashes to be a Hash" unless h.is_a?(Hash)}
248: raise ArgumentError, "expected a key_nam that is a String" unless key_name.is_a? String
249: raise ArgumentError, "expected a value_name that is a String" unless value_name.is_a? String
250: raise ArgumentError, "expected a mappings that is an Hash" unless mappings.is_a? Hash
251: params = {}
252: arr_of_hashes.each_with_index do |hash, i|
253: hash.each do |attribute, value|
254: params["#{key}.#{i+1}.#{key_name}"] = mappings.fetch(attribute, attribute)
255: if !value.nil?
256: if value.is_a? Array
257: value.each_with_index do |item, j|
258: params["#{key}.#{i+1}.#{value_name}.#{j+1}"] = item.to_s
259: end
260: else
261: params["#{key}.#{i+1}.#{value_name}"] = value.to_s
262: end
263: end
264: end
265: end
266: params
267: end