Sha256: 3d2931ab3a5940e64f3df956959275f6d5960554ce460798e7879f8452f6a02c

Contents?: true

Size: 720 Bytes

Versions: 1

Compression:

Stored size: 720 Bytes

Contents

# encoding: UTF-8
require "slugize/version"

module Slugize
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slugize-0.0.1 lib/slugize.rb