Sha256: 2fa660d811fc7453c4221ed3026b2e50c83f11b2e26b814bc970d69d341463e2

Contents?: true

Size: 1017 Bytes

Versions: 15

Compression:

Stored size: 1017 Bytes

Contents

require "pact_broker/domain/group"

module PactBroker
  module Pacticipants
    class FindPotentialDuplicatePacticipantNames
      attr_reader :new_name, :existing_names

      def initialize(new_name, existing_names)
        @new_name = new_name
        @existing_names = existing_names
      end

      def self.call(new_name, existing_names)
        new(new_name, existing_names).call
      end

      def call
        return [] if existing_names.include?(new_name)

        existing_names.select do | existing_name |
          clean(new_name) == clean(existing_name)
        end
      end

      def clean(name)
        self.class.split(name).collect{|w| w.chomp("s") } - ["api", "provider", "service"]
      end

      def self.split(string)
        string.gsub(/\s/, "_")
              .gsub(/::/, "/")
              .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
              .gsub(/([a-z\d])([A-Z])/, '\1_\2')
              .tr("-", "_")
              .downcase
              .split("_")
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.111.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.109.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.109.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.108.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.107.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.107.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.106.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.105.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.104.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.103.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.102.2 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.102.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.102.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb