asciidoctor-foodogsquared-e.../lib/asciidoctor/helpers.rb

12 lines
399 B
Ruby
Raw Normal View History

# 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