UTF8-less permalink in Ruby

require 'iconv'

String.class_eval do 
  def permalise
    split(" ").map do |s|
      Iconv.iconv("ascii//translit", "utf-8", s).to_s.gsub(/\W+/, '')
    end.join(" ").downcase.strip.gsub(/\ +/, '-')
  end
end

if $0 == __FILE__
  require 'test/unit'
  class StringPermaliseTest < Test::Unit::TestCase
    def test_permalise
      assert_equal "delfin-francois", " delfín François ".permalise
    end
  end
end
Used on an.tisanta.com.

Notes

Show