Sha256: 9de871be7122b1369714ed84fff3616ccf9f06dc788fa36d66e621e0d4d96042

Contents?: true

Size: 706 Bytes

Versions: 7

Compression:

Stored size: 706 Bytes

Contents

module Microformats
  class AbsoluteUri
    attr_accessor :base, :relative

    def initialize(relative, base: nil)
      @base = base
      @relative = relative
      @base = base.strip unless base.nil?
      @relative = relative.strip unless relative.nil?
    end

    def absolutize
      return relative if base.nil?
      return base if relative.nil? || relative == ''
      return relative if relative =~ %r{^https?://}
      return base + relative if relative =~ /^#/

      uri = URI.parse(relative)
      uri = URI.join(base.to_s, relative.to_s) if base && !uri.absolute?

      uri.normalize!
      uri.to_s
    rescue URI::BadURIError, URI::InvalidURIError
      relative.to_s
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
microformats-4.5.0 lib/microformats/absolute_uri.rb
microformats-4.4.1 lib/microformats/absolute_uri.rb
microformats-4.3.1 lib/microformats/absolute_uri.rb
microformats-4.2.1 lib/microformats/absolute_uri.rb
microformats-4.2.0 lib/microformats/absolute_uri.rb
microformats-4.1.0 lib/microformats/absolute_uri.rb
microformats-4.0.9 lib/microformats/absolute_uri.rb