Sha256: d46c46cb3e37a098d38607140d9f7709ba84cf4e9050759b68ba916662c8c2c5

Contents?: true

Size: 382 Bytes

Versions: 34

Compression:

Stored size: 382 Bytes

Contents

class String
  def optionize(sep = '-')
    result = downcase.strip

    # Turn unwanted chars into the separator
    result.gsub!(/[^a-z0-9\-_]+/, sep)
    re_sep = Regexp.escape(sep)

    # No more than one of the separator in a row.
    result.gsub!(/#{re_sep}{2,}/, sep)

    result.underscore
  end
  alias_method :slugify, :optionize
  alias_method :systemize, :optionize
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.44 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.43 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.42 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.41 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.40 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.39 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.38 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.37 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.36 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.35 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.34 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.33 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.32 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.31 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.30 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.29 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.28 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.27 lib/workarea/ext/freedom_patches/string.rb
workarea-core-3.4.26 lib/workarea/ext/freedom_patches/string.rb