Sha256: a311b2e7fb76b7e66468f9cc8b0932b72af0f9dbffcb525d179f5ce78b398fea

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Branch
  module Name
    module Normalizable
      NON_WORD_CHARS_REGEX = /[\W_]/

      def normalize_branch_name(ticket_description, ticket)
        normalized_ticket_description = normalize_ticket_description ticket_description
        return normalized_ticket_description if ticket.blank?

        normalized_ticket = normalize_ticket ticket
        "#{normalized_ticket}#{options[:separator]}#{normalized_ticket_description}"
      end

      private

      def normalize_ticket_description(ticket_description)
        normalize_token ticket_description
      end

      def normalize_ticket(ticket)
        ticket.split(NON_WORD_CHARS_REGEX).filter_map do |token|
          normalize_token(token)
        end.join(options[:separator])
      end

      def normalize_token(token)
        token = token.gsub(NON_WORD_CHARS_REGEX, ' ')
        token = token.strip
          .squeeze(' ')
          .split.join(options[:separator])
        token = token.squeeze(options[:separator])
        token = token.downcase if options[:downcase]
        token
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
branch-name-2.1.0 lib/branch/name/normalizable.rb
branch-name-2.0.1.pre.beta lib/branch/name/normalizable.rb