Method: ATDIS::SeparatedURL.split

Defined in:
lib/atdis/separated_url.rb

.split(full_url) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/atdis/separated_url.rb', line 23

def self.split(full_url)
  uri = URI.parse(full_url)
  url = if (uri.scheme == "http" && uri.port == 80) ||
           (uri.scheme == "https" && uri.port == 443)
          "#{uri.scheme}://#{uri.host}#{uri.path}"
        else
          "#{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}"
        end
  url_params = if uri.query
                 Hash[*CGI.parse(uri.query).map { |k, v| [k.to_sym, v.first] }.flatten]
               else
                 {}
               end
  [url, url_params]
end