Sha256: 864888828dbe782b4b24f56fe6c6cfbdef36fdc342c79ca2eff59c2e30f255f6

Contents?: true

Size: 886 Bytes

Versions: 41

Compression:

Stored size: 886 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 |
          similar?(clean(new_name), clean(existing_name))
        end
      end

      def similar?(new_name, existing_name)
        existing_name.include?(new_name) || new_name.include?(existing_name)
      end

      def clean name #TODO uppercase S
        name.gsub(/s\b/,'').gsub(/s([A-Z])/,'\1').gsub(/[^A-Za-z0-9]/,'').downcase
      end

    end

  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
pact_broker-2.2.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.1.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.1.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.5 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.4 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.3 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.2 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0.beta.8 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0.beta.7 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0.beta.6 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-1.18.0 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0.beta.5 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-1.18.0.beta.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-1.17.2 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-1.17.1 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0.beta.4 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0.beta.3 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb
pact_broker-2.0.0.beta.2 lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb