Sha256: 8604a2914fe481836f1011cb82d09458a45ba44451a52324e99fbe2353890746

Contents?: true

Size: 575 Bytes

Versions: 3

Compression:

Stored size: 575 Bytes

Contents

module Domainatrix
  class Url
    attr_reader :tld, :domain, :subdomain, :path

    def initialize(attrs = {})
      @tld = attrs[:tld]
      @domain = attrs[:domain]
      @subdomain = attrs[:subdomain]
      @path = attrs[:path]
    end

    def canonical(options = {})
      tld_parts = @tld.split(".")
      url = "#{tld_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.3 lib/domainatrix/url.rb
domainatrix-0.0.2 lib/domainatrix/url.rb
domainatrix-0.0.1 lib/domainatrix/url.rb