Module: UrlFormat

Defined in:
lib/url_format.rb,
lib/url_format/version.rb

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.ensure_http_prefix(url) ⇒ Object



13
14
15
16
# File 'lib/url_format.rb', line 13

def self.ensure_http_prefix(url)
  return url if url =~ /\Ahttps?:\/\//
  "http://#{url}"
end

.get_domain(url) ⇒ Object



7
8
9
10
11
# File 'lib/url_format.rb', line 7

def self.get_domain(url)
  host = URI.parse(ensure_http_prefix(url)).host.downcase
  host.start_with?('www.') ? host[4..-1] : host
rescue URI::InvalidURIError, NoMethodError
end