Module: URLHelper

Included in:
EmailCrawler::Scraper
Defined in:
lib/email_crawler/url_helper.rb

Constant Summary collapse

DOMAIN_REGEXP =
%r(https://([^/]+))i
WWW_REGEXP =
/\Awww[.]/i

Instance Method Summary collapse

Instance Method Details

#extract_domain_from(url, www = false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/email_crawler/url_helper.rb', line 7

def extract_domain_from(url, www = false)
  uri = begin
          URI(url)
        rescue URI::InvalidURIError
          return
        end
  host = uri.host || url[DOMAIN_REGEXP, 1].to_s

  if www || host !~ WWW_REGEXP
    host.downcase
  else
    $POSTMATCH.downcase
  end
end