Class: PactBroker::Pacticipants::FindPotentialDuplicatePacticipantNames

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_name, existing_names) ⇒ FindPotentialDuplicatePacticipantNames

Returns a new instance of FindPotentialDuplicatePacticipantNames.



11
12
13
14
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 11

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

Instance Attribute Details

#existing_namesObject (readonly)

Returns the value of attribute existing_names.



9
10
11
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 9

def existing_names
  @existing_names
end

#new_nameObject (readonly)

Returns the value of attribute new_name.



9
10
11
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 9

def new_name
  @new_name
end

Class Method Details

.call(new_name, existing_names) ⇒ Object



16
17
18
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 16

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

Instance Method Details

#callObject



20
21
22
23
24
25
26
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 20

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

  existing_names.select do | existing_name |
    similar?(clean(new_name), clean(existing_name))
  end
end

#clean(name) ⇒ Object

TODO uppercase S



32
33
34
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 32

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

#similar?(new_name, existing_name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 28

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