Sha256: c9748e98a2062e1400d8bc0fd2812330d5d9b8301cf7cf8953cab558c57db2a0
Contents?: true
Size: 1.36 KB
Versions: 3
Compression:
Stored size: 1.36 KB
Contents
module Domainatrix class Url attr_accessor :public_suffix, :domain, :subdomain, :path, :url, :scheme, :host, :ip_address 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] || '' @ip_address = attrs[:ip_address] 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].compact.reject{|s|s==''}.join('.') end alias domain_with_tld domain_with_public_suffix def to_s if @scheme.nil? || @scheme.empty? scheme = '' else scheme = "#{@scheme}://" end parts = [] parts << @subdomain if @subdomain and !@subdomain.empty? parts << @domain if @domain and !@domain.empty? parts << @public_suffix if @public_suffix and !@public_suffix.empty? "#{scheme}#{parts.join('.')}#{@path}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
shadowbq-domainatrix-0.0.14 | lib/domainatrix/url.rb |
shadowbq-domainatrix-0.0.12 | lib/domainatrix/url.rb |
shadowbq-domainatrix-0.0.11 | lib/domainatrix/url.rb |