Module: Absolutely

Defined in:
lib/absolutely.rb,
lib/absolutely/uri.rb,
lib/absolutely/version.rb

Defined Under Namespace

Classes: ArgumentError, Error, InvalidURIError, URI

Constant Summary collapse

VERSION =
'6.0.0'

Class Method Summary collapse

Class Method Details

.to_abs(base:, relative:) ⇒ String

Convert a relative path to an absolute URI.

Examples:

Absolutely.to_abs(base: 'https://example.com', relative: '/foo')
#=> "https://example.com/foo"

Parameters:

  • base (String)

    an absolute URI used to resolve relative path

  • relative (String)

    a relative path

Returns:

  • (String)


23
24
25
# File 'lib/absolutely.rb', line 23

def self.to_abs(base:, relative:)
  uri(base: base, relative: relative).to_abs
end

.uri(base:, relative:) ⇒ Absolutely::URI

Create an Absolutely::URI from a base URI and a relative path.

Examples:

uri = Absolutely.uri(base: 'https://example.com', relative: '/foo')
puts uri.to_abs
#=> "https://example.com/foo"

Parameters:

  • base (String)

    an absolute URI used to resolve relative path

  • relative (String)

    a relative path

Returns:



37
38
39
# File 'lib/absolutely.rb', line 37

def self.uri(base:, relative:)
  URI.new(base: base, relative: relative)
end