lib/urlize.rb in Urlize-0.1.3 vs lib/urlize.rb in Urlize-0.2.0

- old
+ new

@@ -1,20 +1,20 @@ module Urlize - require 'uri' - require 'cgi' - def self.read(url) - parsed_uri = URI.parse(url) + parsed_uri = URI::parse(URI.encode(url)) host = parsed_uri.host.index("www.") ? parsed_uri.host.gsub(/www\./, "") : parsed_uri.host - query = CGI.parse(parsed_uri.query) + query = CGI.parse(parsed_uri.query) if !parsed_uri.query.blank? 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") + + if query + output[:search_term] = self.humanize(query["q"]) if query.has_key?("q") + output[:search_term] = self.humanize(query["p"]) if query.has_key?("p") + end output end def self.domain(url) @parsed = self.read(url) @@ -30,7 +30,6 @@ phrase = phrase.gsub(/\+/, " ") else end phrase[0] end - end \ No newline at end of file