mirror of
https://github.com/foo-dogsquared/website.git
synced 2025-01-31 13:58:05 +00:00
12 lines
399 B
Ruby
12 lines
399 B
Ruby
# frozen_string_literal: true
|
|
|
|
class String
|
|
def to_kebab
|
|
self.gsub(/\s+/, '-') # Replace all spaces with dashes.
|
|
.gsub(/[^a-zA-Z0-9-]/, '') # Remove all non-alphanumerical (and dashes) characters.
|
|
.gsub(/-+/, '-') # Reduce all dashes into only one.
|
|
.gsub(/^-|-+$/, '') # Remove all leading and trailing dashes.
|
|
.downcase
|
|
end
|
|
end
|