Skip to content

Instantly share code, notes, and snippets.

@nelix
Created January 11, 2013 04:35
Show Gist options
  • Select an option

  • Save nelix/4507977 to your computer and use it in GitHub Desktop.

Select an option

Save nelix/4507977 to your computer and use it in GitHub Desktop.
make urls match more.
def project_item(project)
url = project.devurl
if url.include?('*')
return [url] # User knows what they are doing
end
unless url.blank?
begin
uri = URI(project.devurl)
unless (uri.scheme == 'http') or (uri.scheme == 'https')
uri.scheme = 'http'
end
url = uri.to_s
if uri.host.starts_with?('www.')
uri.host.gsub!('www.', '')
url2 = uri.to_s
else
uri.host = 'www.' + uri.host
url2 = uri.to_s
end
url += url.ends_with?('/') ? '*' : '/*'
url2 += url2.ends_with?('/') ? '*' : '/*'
return [url, url2]
rescue URI::Error
# Don't care.
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment