Class: Domainatrix::Url
- Inherits:
-
Object
- Object
- Domainatrix::Url
- Defined in:
- lib/domainatrix/url.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#host ⇒ Object
Returns the value of attribute host.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#path ⇒ Object
Returns the value of attribute path.
-
#public_suffix ⇒ Object
Returns the value of attribute public_suffix.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#subdomain ⇒ Object
Returns the value of attribute subdomain.
-
#url ⇒ Object
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.
- #to_s ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Url
Returns a new instance of Url.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/domainatrix/url.rb', line 6 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 |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def domain @domain end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def host @host end |
#ip_address ⇒ Object
Returns the value of attribute ip_address.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def ip_address @ip_address end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def path @path end |
#public_suffix ⇒ Object
Returns the value of attribute public_suffix.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def public_suffix @public_suffix end |
#scheme ⇒ Object
Returns the value of attribute scheme.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def scheme @scheme end |
#subdomain ⇒ Object
Returns the value of attribute subdomain.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def subdomain @subdomain end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/domainatrix/url.rb', line 4 def url @url end |
Instance Method Details
#canonical(options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/domainatrix/url.rb', line 18 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
30 31 32 |
# File 'lib/domainatrix/url.rb', line 30 def domain_with_public_suffix [@domain, @public_suffix].compact.reject{|s|s==''}.join('.') end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/domainatrix/url.rb', line 35 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 |