rsl/stringex · GitHub

Posted . Visible to the public.

Stringex is a gem that offers some extensions to Ruby's String class. Ruby 1.9 compatible, and knows its way around unicode and fancy characters.

Examples for stringex's String#to_url method:

# A simple prelude
"simple English".to_url => "simple-english"
"it's nothing at all".to_url => "its-nothing-at-all"
"rock & roll".to_url => "rock-and-roll"

# Let's show off
"$12 worth of Ruby power".to_url => "12-dollars-worth-of-ruby-power"
"10% off if you act now".to_url => "10-percent-off-if-you-act-now"

# You don't even wanna trust Iconv for this next part
"kick it en Français".to_url => "kick-it-en-francais"
"rock it Español style".to_url => "rock-it-espanol-style"
"tell your readers 你好".to_url => "tell-your-readers-ni-hao"

The above conversions of special chars, like ampersand (&) to "and", can also be docked to I18n Show archive.org snapshot (configured explicitly on plain Ruby, or use .yml files for Rails):

"one & two".convert_miscellaneous_characters # => "one and two"
"my words".convert_miscellaneous_html_entities # => "my words"

I18n.locale = :da
"one & two".convert_miscellaneous_characters # => "one og two"
"my words".convert_miscellaneous_html_entities # => "my mellemrum words"
Arne Hartherz
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2013-02-15 12:53)