Method: Pingpp::Util.flatten_params

Defined in:
lib/pingpp/util.rb

.flatten_params(params, parent_key = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/pingpp/util.rb', line 94

def self.flatten_params(params, parent_key=nil)
  result = []
  params.each do |key, value|
    calculated_key = parent_key ? "#{parent_key}[#{key}]" : "#{key}"
    if value.is_a?(Hash)
      result += flatten_params(value, calculated_key)
    elsif value.is_a?(Array)
      result += flatten_params_array(value, calculated_key)
    else
      result << [calculated_key, value]
    end
  end
  result
end