Class: Adomain

Inherits:
Object
  • Object
show all
Defined in:
lib/adomain.rb,
lib/adomain/version.rb

Constant Summary collapse

ADDRESSABLE_WARNING =
%{
  WARNING: breaking change planned:
    Adomain will catch Addressable::URI::InvalidURIError.
    This error will be caught in version 0.2.
    Any code relying on the error will break.
}.gsub(/\s+/, ' ').strip
VERSION =
"0.1.2"

Class Method Summary collapse

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"


21
22
23
# File 'lib/adomain.rb', line 21

def [](string, domain = false, www = false)
  domain(string, domain, www)
end

.domain(string, domain = true, www = false) ⇒ Object

domain is the base method for only the domain from parse_for_domain

Adomain.domain "http://www.xyz.com" # => "xyz.com"
Adomain.domain "http://abc.xyz.com" # => "xyz.com"
Adomain.domain "http://xyz.com"     # => "xyz.com"


29
30
31
32
# File 'lib/adomain.rb', line 29

def domain(string, domain = true, www = false)
  opts = { :keep_www => www, :strip_subdomain => domain }
  parse_for_domain(string, opts)
end

.subdomain(string, www = false) ⇒ Object

subdomain is a convenience method for the domain with any subdomain except “www” from parse_for_domain

Adomain.subdomain "http://www.xyz.com" # => "xyz.com"
Adomain.subdomain "http://abc.xyz.com" # => "abc.xyz.com"
Adomain.subdomain "http://xyz.com"     # => "xyz.com"


39
40
41
# File 'lib/adomain.rb', line 39

def subdomain(string, www = false)
  domain(string, false, www)
end

.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 "http://www.xyz.com" # => "www.xyz.com"
Adomain.subdomain_www "http://abc.xyz.com" # => "abc.xyz.com"
Adomain.subdomain_www "http://xyz.com"     # => "xyz.com"


48
49
50
# File 'lib/adomain.rb', line 48

def subdomain_www(string)
  subdomain(string, true)
end