class String
Public Instance Methods
removeaccents()
click to toggle source
Remove the accents from the string. Uses String::ACCENTS_MAPPING as the source map.
# File lib/remove_accents/base.rb, line 20 def removeaccents str = String.new(self) RemoveAccents.new.config["replacements"].each {|letter,accents| packed = accents.pack('U*') rxp = Regexp.new("[#{packed}]", nil) str.gsub!(rxp, letter) } str end
urlize(options = {})
click to toggle source
Convert a string to a format suitable for a URL without ever using escaped characters. It calls strip, removeaccents, downcase (optional) then removes the spaces (optional) and finally removes any characters matching the default regexp (/[^-_A-Za-z0-9]/).
Options
-
:downcase => call downcase on the string (defaults to true)
-
:convert_spaces => Convert space to underscore (defaults to false)
-
:regexp => The regexp matching characters that will be converting to an empty string (defaults to /[^-_A-Za-z0-9]/)
# File lib/remove_accents/base.rb, line 41 def urlize(options = {}) options[:downcase] ||= false options[:convert_spaces] ||= false options[:regexp] ||= /[^-_A-Za-z0-9]/ str = self.strip.removeaccents str.downcase! if options[:downcase] str.gsub!(/\ /,'_') if options[:convert_spaces] str.gsub(options[:regexp], '') end