Sha256: cd532fcd70a7ac9b72fd08ab66870b2b9eec473a813f1a69bde1902b7f8cc50d

Contents?: true

Size: 684 Bytes

Versions: 3

Compression:

Stored size: 684 Bytes

Contents

module Microformats2
  class AbsoluteUri
    attr_accessor :base, :relative

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

    def absolutize
      #TODO: i'm sure this could be improved a bit
      return nil if relative.nil? or relative == ""
      return relative if relative =~ /^https?:\/\//

      uri = URI.parse(relative)

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

      uri.normalize!
      uri.to_s

    rescue URI::BadURIError, URI::InvalidURIError => e
      relative.to_s
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
microformats2-3.1.0 lib/microformats2/absolute_uri.rb
microformats2-3.0.1 lib/microformats2/absolute_uri.rb
microformats2-3.0.0 lib/microformats2/absolute_uri.rb