X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Futils%2Fextends.rb;h=08278261fdfa435b21991a069cd66cb7664b9d31;hb=7b792bea7a644309623d67b5d49528ae13da3e7b;hp=11ebfc613fd7d6022e5e0bbc61e1ae6918669285;hpb=b22038a43a626915c6f70debf63f732053309a75;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index 11ebfc61..08278261 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -380,6 +380,18 @@ class ::String return txt end + + # Removes non-ASCII symbols from string + def remove_nonascii(replace='') + encoding_options = { + :invalid => :replace, # Replace invalid byte sequences + :undef => :replace, # Replace anything not defined in ASCII + :replace => replace, + :universal_newline => true # Always break lines with \n + } + + self.encode(Encoding.find('ASCII'), encoding_options) + end end # Extensions to the Regexp class, with some common and/or complex regular