Class: Adomain
- Inherits:
-
Object
- Object
- Adomain
- Defined in:
- lib/adomain.rb,
lib/adomain/version.rb
Constant Summary collapse
- VERSION =
"0.2.1"
Class Method Summary collapse
-
.[](string, domain = false, www = false) ⇒ Object
-
is a convenience method to subdomain the URL, or optionally domain or subdomain_www.
-
-
.domain(string, domain = true, www = false) ⇒ Object
domain is the base method for only the domain from parse_for_domain Adomain.domain “www.xyz.com” # => “xyz.com” Adomain.domain “abc.xyz.com” # => “xyz.com” Adomain.domain “xyz.com” # => “xyz.com”.
-
.path(string) ⇒ Object
path is a wrapper around Addressable::URI’s path it is only included for convenience.
-
.scheme(string) ⇒ Object
scheme is a wrapper around Addressable::URI’s scheme it is only included for convenience.
-
.subdomain(string, www = false) ⇒ Object
subdomain is a convenience method for the domain with any subdomain except “www” from parse_for_domain Adomain.subdomain “www.xyz.com” # => “xyz.com” Adomain.subdomain “abc.xyz.com” # => “abc.xyz.com” Adomain.subdomain “xyz.com” # => “xyz.com”.
-
.subdomain_www(string) ⇒ Object
subdomain_www is a convenience method for the domain with any subdomain including “www” from parse_for_domain Adomain.subdomain_www “www.xyz.com” # => “www.xyz.com” Adomain.subdomain_www “abc.xyz.com” # => “abc.xyz.com” Adomain.subdomain_www “xyz.com” # => “xyz.com”.
Class Method Details
.[](string, domain = false, www = false) ⇒ Object
-
is a convenience method to subdomain the URL,
or optionally domain or subdomain_www.
Adomain["http://abc.xyz.com"] # => "abc.xyz.com"
Adomain["http://abc.xyz.com", true] # => "xyz.com"
Adomain["http://www.xyz.com", false, true] # => "www.xyz.com"
Adomain["http://abc.xyz.com", false, false] # => "abc.xyz.com"
13 14 15 |
# File 'lib/adomain.rb', line 13 def [](string, domain = false, www = false) domain(string, domain, www) end |
.domain(string, domain = true, www = false) ⇒ Object
21 22 23 24 |
# File 'lib/adomain.rb', line 21 def domain(string, domain = true, www = false) opts = { :keep_www => www, :strip_subdomain => domain } parse_for_domain(string, opts) end |
.path(string) ⇒ Object
path is a wrapper around Addressable::URI’s path it is only included for convenience
54 55 56 57 58 |
# File 'lib/adomain.rb', line 54 def path(string) Addressable::URI.parse(string).path rescue Addressable::URI::InvalidURIError => e nil end |
.scheme(string) ⇒ Object
scheme is a wrapper around Addressable::URI’s scheme it is only included for convenience
46 47 48 49 50 |
# File 'lib/adomain.rb', line 46 def scheme(string) Addressable::URI.parse(string).scheme rescue Addressable::URI::InvalidURIError => e nil end |
.subdomain(string, www = false) ⇒ Object
31 32 33 |
# File 'lib/adomain.rb', line 31 def subdomain(string, www = false) domain(string, false, www) end |
.subdomain_www(string) ⇒ Object
40 41 42 |
# File 'lib/adomain.rb', line 40 def subdomain_www(string) subdomain(string, true) end |