def query_values(options={})
defaults = {:notation => :subscript}
options = defaults.merge(options)
if ![:flat, :dot, :subscript].include?(options[:notation])
raise ArgumentError,
"Invalid notation. Must be one of: [:flat, :dot, :subscript]."
end
return nil if self.query == nil
return (self.query.split("&").map do |pair|
pair.split("=")
end).inject({}) do |accumulator, pair|
key, value = pair
value = true if value.nil?
key = self.class.unencode_component(key)
if value != true
value = self.class.unencode_component(value).gsub(/\+/, " ")
end
if options[:notation] == :flat
if accumulator[key]
raise ArgumentError, "Key was repeated: #{key.inspect}"
end
accumulator[key] = value
else
if options[:notation] == :dot
array_value = false
subkeys = key.split(".")
elsif options[:notation] == :subscript
array_value = !!(key =~ /\[\]$/)
subkeys = key.split(/[\[\]]+/)
end
current_hash = accumulator
for i in 0...(subkeys.size - 1)
subkey = subkeys[i]
current_hash[subkey] = {} unless current_hash[subkey]
current_hash = current_hash[subkey]
end
if array_value
current_hash[subkeys.last] = [] unless current_hash[subkeys.last]
current_hash[subkeys.last] << value
else
current_hash[subkeys.last] = value
end
end
accumulator
end
end