Sha256: 98ca9c4b4915da8ab68b329c2d2e9ad097fb47093aeecff8db7b93ce15dbb7ce

Contents?: true

Size: 888 Bytes

Versions: 22

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

module Dsu
  module Support
    module TransformProjectName
      TRANSFORM_PROJECT_NAME_REGEX = %r{[^/\w\s]|_}
      TRANSFORM_PROJECT_NAME_SEPARATOR = '-'

      module_function

      def transform_project_name(project_name, options: {})
        normalized_name = project_name
          .gsub(TRANSFORM_PROJECT_NAME_REGEX, ' ')   # Replace non-word characters and underscores with space
          .strip                                     # Remove leading and trailing spaces
          .squeeze(' ')                              # Convert consecutive spaces to a single space
          .tr(' ', TRANSFORM_PROJECT_NAME_SEPARATOR) # Replace spaces with hyphens
          .squeeze(TRANSFORM_PROJECT_NAME_SEPARATOR) # Ensure no consecutive hyphens

        normalized_name.downcase! if options[:downcase]
        normalized_name
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/support/transform_project_name.rb
dsu-3.0.4 lib/dsu/support/transform_project_name.rb
dsu-3.0.3 lib/dsu/support/transform_project_name.rb
dsu-3.0.1 lib/dsu/support/transform_project_name.rb
dsu-3.0.0 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.beta.3 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.beta.2 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.beta.1 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.beta.0 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.12 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.11 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.10 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.9 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.8 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.7 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.6 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.5 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.4 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.3 lib/dsu/support/transform_project_name.rb
dsu-3.0.0.alpha.2 lib/dsu/support/transform_project_name.rb