Module: UrlFormatter

Defined in:
lib/url_formatter.rb,
lib/url_formatter/version.rb,
lib/url_formatter/model_additions.rb

Defined Under Namespace

Modules: ModelAdditions

Constant Summary

VERSION =
"0.0.1.alpha"

Class Method Summary collapse

Class Method Details

.format_url(url) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/url_formatter.rb', line 6

def self.format_url(url)
  if url.to_s !~ url_regexp && "http://#{url}" =~ url_regexp
    "http://#{url}"
  else
    url
  end
end

.url_regexpObject



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

def self.url_regexp
  /^https?:\/\/([^\s:@]+:[^\s:@]*@)?[-[[:alnum:]]]+(\.[-[[:alnum:]]]+)+\.?(:\d{1,5})?([\/?]\S*)?$/iux
end