Read more

rsl/stringex · GitHub

Arne Hartherz
February 15, 2013Software engineer at makandra GmbH

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.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

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"
Posted by Arne Hartherz to makandra dev (2013-02-15 13:53)