class MiddleSquid::URI

Provides distinguishable host and path for the blacklists.

@see rubydoc.info/gems/addressable/Addressable/URI

Constants

DOT
SLASH

Public Instance Methods

cleanhost() click to toggle source

@return [String]

# File lib/middle_squid/uri.rb, line 10
def cleanhost
  clean = normalized_host.force_encoding Encoding::UTF_8
  clean.sub! /\Awww\./, ''
  clean.sub! /\.+\z/, ''
  clean.insert 0, DOT
  clean
end
cleanpath() click to toggle source

@return [String]

# File lib/middle_squid/uri.rb, line 19
def cleanpath
  dirty = normalized_path.force_encoding Encoding::UTF_8
  p = Pathname.new(dirty).cleanpath

  file = p.basename('.*').to_s.downcase
  p = p.dirname if %w[index default].include? file

  clean = p.to_s[1..-1]
  clean << SLASH unless clean.empty?
  clean
end