Class: Httply::Utilities::Uri

Inherits:
Object
  • Object
show all
Defined in:
lib/httply/utilities/uri.rb

Class Method Summary collapse

Class Method Details

.correct_host(host) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/httply/utilities/uri.rb', line 6

def correct_host(host)
  if !host.to_s.empty?
    host                    =   host =~ /^http(s)?:\/\//i ? host : "https://#{host}"
  end
      
  return host
end

.parse_host(url) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/httply/utilities/uri.rb', line 14

def parse_host(url)
  host                      =   nil
      
  if host.to_s.empty? && url =~ /^http(s)?:\/\//
    uri                     =   URI(url)
    host                    =   "#{uri.scheme}://#{uri.host}"
  end
      
  return host
end

.to_path(path) ⇒ Object



25
26
27
28
# File 'lib/httply/utilities/uri.rb', line 25

def to_path(path)
  path                      =   path =~ /^http(s)?:\/\// ? URI(path).path : path
  path                      =   path =~ /^\// ? path : "/#{path}"
end