Class: Domainatrix::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/domainatrix/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Url

Returns a new instance of Url.



5
6
7
8
9
10
11
12
13
# File 'lib/domainatrix/url.rb', line 5

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

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



3
4
5
# File 'lib/domainatrix/url.rb', line 3

def domain
  @domain
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/domainatrix/url.rb', line 3

def host
  @host
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/domainatrix/url.rb', line 3

def path
  @path
end

#public_suffixObject (readonly)

Returns the value of attribute public_suffix.



3
4
5
# File 'lib/domainatrix/url.rb', line 3

def public_suffix
  @public_suffix
end

#schemeObject (readonly)

Returns the value of attribute scheme.



3
4
5
# File 'lib/domainatrix/url.rb', line 3

def scheme
  @scheme
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



3
4
5
# File 'lib/domainatrix/url.rb', line 3

def subdomain
  @subdomain
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/domainatrix/url.rb', line 3

def url
  @url
end

Instance Method Details

#canonical(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/domainatrix/url.rb', line 15

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

#domain_with_public_suffixObject Also known as: domain_with_tld



27
28
29
# File 'lib/domainatrix/url.rb', line 27

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