Module: Gemmy::Patches::StringPatch::InstanceMethods::AsciiOnly

Defined in:
lib/gemmy/patches/string_patch.rb

Instance Method Summary collapse

Instance Method Details

#ascii_only(alt = '') ⇒ Object

facets remove non ascii characters



259
260
261
262
263
264
265
266
267
# File 'lib/gemmy/patches/string_patch.rb', line 259

def ascii_only(alt='')
  encoding_options = {
    :invalid                     => :replace,  # Replace invalid byte sequences
    :undef                       => :replace,  # Replace anything not defined in ASCII
    :replace                     => alt,       # Use a blank for those replacements
    :UNIVERSAL_NEWLINE_DECORATOR => true       # Always break lines with \n
  }
  self.encode(Encoding.find('ASCII'), encoding_options)
end