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

+ (Object) format_url(url)



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

+ (Object) url_regexp



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