lib/monkey_patches.rb in zeke-monkey_patches-0.1.15 vs lib/monkey_patches.rb in zeke-monkey_patches-0.1.16

- old
+ new

@@ -55,16 +55,16 @@ # Removes HTML tags from a string def strip_tags self.gsub(/<\/?[^>]*>/, "") end - # Remove first instance of string + # Removes first instance of string def nix(string) self.sub(string, "") end - # Remove all instances of string + # Removes all instances of string def gnix(string) self.gsub(string, "") end # Prepends 'http://' to the beginning of non-empty strings that don't already have it. @@ -99,18 +99,26 @@ out << end_string out.join(" ") end end + # Extracts domain name from a URL def domain url = self.dup url=~(/^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)/) ? $1 : url end + # Extracts domain name (sans 'www.') from a URL string def domain_without_www self.domain.remove_http_and_www end + # Returns true or false depending on whether a string appears to be a URL + def valid_url? + !self.match(/https?:\/\/([^\/]+)(.*)/).nil? + end + + # Removes tab characters and instances of more than one space def remove_whitespace self.gnix("\t").split(" ").remove_blanks.join(" ") end def replace_wonky_characters_with_ascii