Class: URIParser

Inherits:
Object
  • Object
show all
Defined in:
lib/uri_parser.rb,
lib/uri_parser/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#path_and_queryObject



8
9
10
11
12
13
14
# File 'lib/uri_parser.rb', line 8

def path_and_query
  @path_and_query ||= if query.empty?
    path
  else
    "#{path}?#{query}"
  end
end

#query_paramsObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/uri_parser.rb', line 16

def query_params
  @query_params ||= begin
    k_v_pairs = query.split('&')

    {}.tap do |hash|
      k_v_pairs.each do |kv|
        key, value = kv.split('=')
        hash[CGI.unescape(key)] = CGI.unescape(value)
      end
    end
  end
end