Sha256: 842eb69b15317c490c4abc071caac785c3c286a75cef087287557a78001c7c6e

Contents?: true

Size: 319 Bytes

Versions: 8

Compression:

Stored size: 319 Bytes

Contents

module Dao
  class Slug < ::String
    def Slug.for(*args)
      string = args.flatten.compact.join('-')
      words = string.to_s.scan(%r/\w+/)
      words.map!{|word| word.gsub(%r/[^0-9a-zA-Z_-]/, '')}
      words.delete_if{|word| word.nil? or word.strip.empty?}
      new(words.join('-').downcase)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dao-3.3.0 lib/dao/slug.rb
dao-3.2.0 lib/dao/slug.rb
dao-3.1.2 lib/dao/slug.rb
dao-3.1.1 lib/dao/slug.rb
dao-3.1.0 lib/dao/slug.rb
dao-2.2.3 lib/dao/slug.rb
dao-2.1.0 lib/dao/slug.rb
dao-2.0.0 lib/dao/slug.rb