Module: Enumerable

Defined in:
lib/freckly/ext/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#build_query_params(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/freckly/ext/enumerable.rb', line 2

def build_query_params(options={})
  escape = options[:escape]
  previous_base = options[:base]
  parts = []

  self.to_a.each do |key, value|
    base = build_base(key, previous_base)

    case value
    when Array
      values = value.map(&:strip).join(",")
      parts << build_param(base, values)
    when Hash
      parts << value.build_query_params(:escape => false, :base => base)
    else
      parts << (escape ? build_escaped_param(base, value) : build_param(base, value))
    end
  end

  parts.join("&")
end