module Urlize require 'uri' require 'cgi' def self.read(url) parsed_uri = URI.parse(url) host = parsed_uri.host.index("www.") ? parsed_uri.host.gsub(/www\./, "") : parsed_uri.host query = CGI.parse(parsed_uri.query) output = { :scheme => parsed_uri.scheme, :host => host, } output[:search_term] = self.humanize(query["q"]) if query.has_key?("q") output[:search_term] = self.humanize(query["p"]) if query.has_key?("p") output end def self.domain(url) @parsed = self.read(url) output = @parsed[:host] output << " (#{@parsed[:search_term]})" if @parsed[:search_term] output end protected def self.humanize(phrase) if phrase.index("%20") phrase = phrase.gsub(/%20/, " ") phrase = phrase.gsub(/\+/, " ") else end phrase[0] end end