Sha256: b9e6b1e33f265d4da98a9ef077b69d9afb45ee29af25f3ff738d0e2bca1ba96a

Contents?: true

Size: 468 Bytes

Versions: 18

Compression:

Stored size: 468 Bytes

Contents

# -*- encoding : utf-8 -*-
module Dao
  class Slug < ::String
    Join = '-'

    def Slug.for(*args)
      options = args.last.is_a?(Hash) ? args.pop : {}
      join = options[:join]||options['join']||Join
      string = args.flatten.compact.join(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(join).downcase)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dao-8.0.1 lib/dao/slug.rb
dao-8.0.0 lib/dao/slug.rb
dao-7.0.0 lib/dao/slug.rb
dao-5.6.1 lib/dao/slug.rb
dao-5.5.2 lib/dao/slug.rb
dao-5.5.1 lib/dao/slug.rb
dao-5.5.0 lib/dao/slug.rb
dao-5.4.0 lib/dao/slug.rb
dao-5.3.3 lib/dao/slug.rb
dao-5.3.2 lib/dao/slug.rb
dao-5.3.0 lib/dao/slug.rb
dao-5.2.1 lib/dao/slug.rb
dao-5.1.2 lib/dao/slug.rb
dao-5.1.1 lib/dao/slug.rb
dao-5.0.0 lib/dao/slug.rb
dao-4.6.4 lib/dao/slug.rb
dao-4.4.4 lib/dao/slug.rb
dao-4.4.2 lib/dao/slug.rb