Sha256: 54cd78c29654c4ff5d58e7fe9194a40eadccb4d224b953e183d5514569429bc2

Contents?: true

Size: 873 Bytes

Versions: 3

Compression:

Stored size: 873 Bytes

Contents

module Domainatrix
  class Url
    attr_reader :public_suffix, :domain, :subdomain, :path, :url, :scheme, :host

    def initialize(attrs = {})
      @scheme = attrs[:scheme]
      @host = attrs[:host]
      @url = attrs[:url]
      @public_suffix = attrs[:public_suffix]
      @domain = attrs[:domain]
      @subdomain = attrs[:subdomain]
      @path = attrs[:path]
    end

    def canonical(options = {})
      public_suffix_parts = @public_suffix.split(".")
      url = "#{public_suffix_parts.reverse.join(".")}.#{@domain}"
      if @subdomain && !@subdomain.empty?
        subdomain_parts = @subdomain.split(".")
        url << ".#{subdomain_parts.reverse.join(".")}"
      end
      url << @path if @path

      url
    end

    def domain_with_public_suffix
      "#{@domain}.#{@public_suffix}"
    end
    alias domain_with_tld domain_with_public_suffix

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
f1sherman-domainatrix-0.0.11 lib/domainatrix/url.rb
f1sherman-domainatrix-0.0.10 lib/domainatrix/url.rb
domainatrix-0.0.10 lib/domainatrix/url.rb