Module: Map::Param
Instance Method Summary collapse
Instance Method Details
#bytesize(string) ⇒ Object
66 |
# File 'lib/map/params.rb', line 66 def bytesize(string) string.bytesize end |
#escape(s) ⇒ Object
73 74 75 |
# File 'lib/map/params.rb', line 73 def escape(s) URI.encode_www_form_component(s) end |
#param_for(value, prefix = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/map/params.rb', line 44 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 |