Method: CrmFormatter::Web#normalize_url

Defined in:
lib/crm_formatter/web.rb

#normalize_url(url) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/crm_formatter/web.rb', line 86

def normalize_url(url)
  return unless url.present?
  uri = URI(url)
  scheme = uri&.scheme
  host = uri&.host
  url = "#{scheme}://#{host}" if host.present? && scheme.present?
  url = "http://#{url}" if url[0..3] != 'http'

  return unless url.present?
  url.gsub!('//', '//www.') unless url.include?('www.')
  url
end