Class: Domainatrix::Url
- Inherits:
-
Object
- Object
- Domainatrix::Url
- Defined in:
- lib/domainatrix/url.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#public_suffix ⇒ Object
readonly
Returns the value of attribute public_suffix.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #canonical(options = {}) ⇒ Object
- #domain_with_public_suffix ⇒ Object (also: #domain_with_tld)
-
#initialize(attrs = {}) ⇒ Url
constructor
A new instance of Url.
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
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
3 4 5 |
# File 'lib/domainatrix/url.rb', line 3 def domain @domain end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/domainatrix/url.rb', line 3 def host @host end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/domainatrix/url.rb', line 3 def path @path end |
#public_suffix ⇒ Object (readonly)
Returns the value of attribute public_suffix.
3 4 5 |
# File 'lib/domainatrix/url.rb', line 3 def public_suffix @public_suffix end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
3 4 5 |
# File 'lib/domainatrix/url.rb', line 3 def scheme @scheme end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
3 4 5 |
# File 'lib/domainatrix/url.rb', line 3 def subdomain @subdomain end |
#url ⇒ Object (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( = {}) 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_suffix ⇒ Object 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 |