Module: Map::Param

Extended by:
Param
Included in:
Param
Defined in:
lib/map/params.rb

Instance Method Summary collapse

Instance Method Details

#bytesize(string) ⇒ Object



56
# File 'lib/map/params.rb', line 56

def bytesize(string) string.bytesize end

#escape(s) ⇒ Object



63
64
65
# File 'lib/map/params.rb', line 63

def escape(s)
  URI.encode_www_form_component(s)
end

#param_for(value, prefix = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/map/params.rb', line 34

def param_for(value, prefix = nil)
  case value
    when Array
      value.map { |v|
        param_for(v, "#{ prefix }[]")
      }.join("&")

    when Hash
      value.map { |k, v|
        param_for(v, prefix ? "#{ prefix }[#{ escape(k) }]" : escape(k))
      }.join("&")

    when String
      raise ArgumentError, "value must be a Hash" if prefix.nil?
      "#{ prefix }=#{ escape(value) }"

    else
      prefix
  end
end