Last active
December 22, 2015 05:07
-
-
Save moskvin/b6abfaaea8e0e5ad9234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'uri' | |
require 'addressable/uri' | |
module SiteUrlHelper | |
def self.site_url_valid? url | |
uri = URI.parse url | |
uri.kind_of? URI::HTTP | |
rescue URI::InvalidURIError | |
false | |
end | |
def self.get_printed_and_normalised url | |
uri = Addressable::URI.parse url | |
uri = Addressable::URI.parse "http://#{url}" unless uri.scheme | |
return nil unless self.site_url_valid? uri.normalized_site | |
[uri.hostname, uri.normalized_site] | |
end | |
end |
Author
moskvin
commented
Dec 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment