File: string_parameterize.rb

package info (click to toggle)
ruby-test-prof 0.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 508 kB
  • sloc: ruby: 4,075; makefile: 4
file content (15 lines) | stat: -rw-r--r-- 402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# frozen_string_literal: true

module TestProf
  # Extend String with #parameterize method
  module StringParameterize
    refine String do
      # Replaces special characters in a string with dashes.
      def parameterize(separator: "-", preserve_case: false)
        gsub(/[^a-z0-9\-_]+/i, separator).tap do |str|
          str.downcase! unless preserve_case
        end
      end
    end
  end
end