Sha256: 6321a2e91ff21a2c8560f372c8afda4287af76df11294b1e1f22e87870e2f689
Contents?: true
Size: 658 Bytes
Versions: 1
Compression:
Stored size: 658 Bytes
Contents
# encoding: UTF-8 require "slugize/version" class String def slugize str = self separator = '-' re_separator = Regexp.escape(separator) str = pl2us(str) str.gsub!(/ /, separator) str.gsub!(/[^\x00-\x7F]+/, '') str.gsub!(/[^a-z0-9\-_\+]+/i, separator) str.gsub!(/#{re_separator}{2,}/, separator) str.gsub!(/^#{re_separator}|#{re_separator}$/, '') str end def pl2us(str) str = self.downcase.strip chars = {'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', 'ż' => 'z'} chars.each do |k,v| str.gsub! /#{k}/, "#{v}" end str end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slugize-0.0.2 | lib/slugize.rb |