lib/much-slug/slug.rb in much-slug-0.1.0 vs lib/much-slug/slug.rb in much-slug-0.1.1
- old
+ new
@@ -1,18 +1,20 @@
-module MuchSlug
- module Slug
- def self.new(string, preprocessor:, separator:, allow_underscores: true)
- regexp_escaped_sep = Regexp.escape(separator)
+# frozen_string_literal: true
- slug = preprocessor.call(string.to_s.dup)
- # Turn unwanted chars into the separator
- slug.gsub!(/[^\w#{regexp_escaped_sep}]+/, separator)
- # Turn underscores into the separator, unless allowing
- slug.gsub!(/_/, separator) unless allow_underscores
- # No more than one of the separator in a row.
- slug.gsub!(/#{regexp_escaped_sep}{2,}/, separator)
- # Remove leading/trailing separator.
- slug.gsub!(/\A#{regexp_escaped_sep}|#{regexp_escaped_sep}\z/, "")
- slug
- end
+module MuchSlug; end
+
+module MuchSlug::Slug
+ def self.new(string, preprocessor:, separator:, allow_underscores: true)
+ regexp_escaped_sep = Regexp.escape(separator)
+
+ slug = preprocessor.call(string.to_s.dup)
+ # Turn unwanted chars into the separator
+ slug.gsub!(/[^\w#{regexp_escaped_sep}]+/, separator)
+ # Turn underscores into the separator, unless allowing
+ slug.gsub!(/_/, separator) unless allow_underscores
+ # No more than one of the separator in a row.
+ slug.gsub!(/#{regexp_escaped_sep}{2,}/, separator)
+ # Remove leading/trailing separator.
+ slug.gsub!(/\A#{regexp_escaped_sep}|#{regexp_escaped_sep}\z/, "")
+ slug
end
end