0.0
No commit activity in last 3 years
No release in over 3 years
You can use this extension to the String class to convert "àéêîôûù" to "aeeiouu".
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0
~> 10.0
>= 0
 Project Readme

Removing Accents In a Ruby String

In short, you can use this extension to the String class to convert "àéêîôûù" to "aeeiouu".

It's fairly easy to convert a string to a URL-safe version. Both PHP and Ruby have a way to do this, but what happens in this case is that extended characters are escaped rather than being replaced and that's often not what I want.

If you're like me, you've probably had many occasions where you wanted to get a 7bits ASCII version of a string where the accents are converted to the base letter. For example, you want to give each user his page at : [domain.com]/[name]. When the name is "Steve Smith", that's not a problem, but what if the name is "François Léveillé" ?

What you want in this case is "francois_leveille" or "francoisleveille" and this is where this script will help you.

Installation

Add this line to your application's Gemfile:

gem 'remove_accents'

And then execute:

$ bundle

Or install it yourself as:

$ gem install remove_accents

Usage

===========

require 'remove_accents'

# Set a sample string to test things out
```ruby
mystring = "Ceci Est UN test : éàòù"
```

# The removeaccents method simple removes the accents and returns the string
```ruby
mystring.removeaccents
```

# The urlize method not only calls removeaccents, 
# but also a bunch of others to make it truly URL-ready.
mystring.urlize

# You can customize urlize with options:
# :downcase => true
#     will convert entire string to lowercase
# :convert_spaces => true
#     will convert space to underscore
# :regexp => //
#     matching characters will be removed

mystring.urlize({:downcase => true})