Sha256: 470506187b29f80a2a5ba715299870413e3f7f6012e969678fb55919e214ffa9
Contents?: true
Size: 740 Bytes
Versions: 2
Compression:
Stored size: 740 Bytes
Contents
module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module String #:nodoc: module Slugify # Action can by either :generate or :increment. Generate will generate from the string as though it were a new slug. # Increment will increment the integer at the end of the slug. def slugify(action=:generate) case action when :generate s = self.gsub(/\s+/, ' ') s.strip! s.gsub!(' ', '-') s.gsub!('&', 'and') s.gsub!(/[^\w-]/u, '') s.mb_chars.downcase.to_s when :increment self.slugify.gsub(/^(.*?)-?(\d*)$/) { "#{$1}-#{$2.to_i.next}" } end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
seamusabshere-slugify-1.0.1 | lib/slugify.rb |
seamusabshere-slugify-1.0.2 | lib/slugify.rb |