Sha256: fc9bd83be337f8c4f3ed1647c9439197698c11791fca1636eb431cf900a69f18

Contents?: true

Size: 897 Bytes

Versions: 2

Compression:

Stored size: 897 Bytes

Contents

require 'pact_broker/domain/group'

=begin

=end

module PactBroker

  module Functions

    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

2 entries across 2 versions & 1 rubygems

Version Path
pact_broker-1.4.0 lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb
pact_broker-1.3.2.rc1 lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb