14 行
331 B
Ruby
14 行
331 B
Ruby
class PostUrlNormaliser
|
|
def self.normalise raw_url
|
|
value = raw_url.to_s.strip
|
|
uri = URI.parse(value)
|
|
return nil unless uri.is_a?(URI::HTTP) && uri.host.present?
|
|
|
|
uri.host = uri.host.downcase
|
|
uri.path = uri.path.sub(/\/\z/, '') if uri.path.present?
|
|
uri.to_s
|
|
rescue URI::InvalidURIError
|
|
nil
|
|
end
|
|
end
|