Sha256: 617fa8e796d93cce027f4a1318088085677b9e42690bc30b62ca4305ac017412

Contents?: true

Size: 911 Bytes

Versions: 15

Compression:

Stored size: 911 Bytes

Contents

# coding: utf-8

require 'cgi'
require 'uri'

require 'fig/user_input_error'

module Fig; end

module Fig::URL
  # From https://www.rfc-editor.org/rfc/rfc1738.txt
  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

  # Encodes components and joins with slashes.
  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

  # URI.parse() doesn't like space characters, unlike most of the world.
  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
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
fig-1.27.10 lib/fig/url.rb
fig-1.27.8 lib/fig/url.rb
fig-1.27.5 lib/fig/url.rb
fig-1.27.4 lib/fig/url.rb
fig-1.27.3 lib/fig/url.rb
fig-1.27.0 lib/fig/url.rb
fig-1.26.1.beta.1 lib/fig/url.rb
fig-1.26.0 lib/fig/url.rb
fig-1.25.1.beta.1 lib/fig/url.rb
fig-1.25.0 lib/fig/url.rb
fig-1.24.1.beta.3 lib/fig/url.rb
fig-1.24.1.beta.2 lib/fig/url.rb
fig-1.24.1.beta.1 lib/fig/url.rb
fig-1.24.0 lib/fig/url.rb
fig-1.23.1.beta.1 lib/fig/url.rb