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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)