Module: NationBuilder::Utils::QueryParams

Defined in:
lib/nationbuilder/utils.rb

Class Method Summary collapse

Class Method Details

.encode(value, key = nil, output = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/nationbuilder/utils.rb', line 5

def encode(value, key = nil, output = {})
  case value
  when Hash  then value.each { |k, v| encode(v, append_key(key, k), output) }
  when Array then value.each { |v|    encode(v, "#{key}[]", output) }
  when nil   then ''
  else
    output[key] = value
  end
  output
end