Module: Fig::URL

Defined in:
lib/fig/url.rb

Class Method Summary collapse

Class Method Details

.append_path_components(base_url, components) ⇒ Object

Encodes components and joins with slashes.



19
20
21
22
23
24
# File 'lib/fig/url.rb', line 19

def self.append_path_components(base_url, components)
  url     = base_url.sub(%r< / \z >x, '')
  encoded = components.map { |component| CGI.escape component }

  return [url, encoded].flatten.join('/')
end

.is_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/fig/url.rb', line 12

def self.is_url?(url)
  # We don't count single-letter "protocols" to allow for Windows drive
  # letters in paths.
  return !! ( url =~ %r< \A [a-z0-9+.-]{2,} : >ix )
end

.parse(url) ⇒ Object

URI.parse() doesn’t like space characters, unlike most of the world.



27
28
29
30
31
32
33
34
# File 'lib/fig/url.rb', line 27

def self.parse(url)
  begin
    return URI.parse(url.gsub ' ', '+')
  rescue URI::InvalidURIError => error
    raise Fig::UserInputError.new \
      %Q<Cannot parse URL "#{url}": #{error.message}>
  end
end