Sha256: 07a447f18aa418ef8fa2e99896fb34fd051a8c0b36aaebe189fbc9ec63765e38

Contents?: true

Size: 740 Bytes

Versions: 3

Compression:

Stored size: 740 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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
domainatrix-0.0.9 lib/domainatrix/url.rb
domainatrix-0.0.8 lib/domainatrix/url.rb
domainatrix-0.0.7 lib/domainatrix/url.rb