Sha256: b5dc2cc179ba580d1fe88233d136deed2d7781b2d806ed5c0bf6bf28a482c027

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 Bytes

Contents

require 'pact_broker/models/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

3 entries across 3 versions & 1 rubygems

Version Path
pact_broker-1.3.1 lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb
pact_broker-1.3.0 lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb
pact_broker-1.2.0 lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb