Class: PactBroker::Functions::FindPotentialDuplicatePacticipantNames
- Inherits:
-
Object
- Object
- PactBroker::Functions::FindPotentialDuplicatePacticipantNames
- Defined in:
- lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb
Instance Attribute Summary collapse
-
#existing_names ⇒ Object
readonly
Returns the value of attribute existing_names.
-
#new_name ⇒ Object
readonly
Returns the value of attribute new_name.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#clean(name) ⇒ Object
TODO uppercase S.
-
#initialize(new_name, existing_names) ⇒ FindPotentialDuplicatePacticipantNames
constructor
A new instance of FindPotentialDuplicatePacticipantNames.
- #similar?(new_name, existing_name) ⇒ Boolean
Constructor Details
#initialize(new_name, existing_names) ⇒ FindPotentialDuplicatePacticipantNames
Returns a new instance of FindPotentialDuplicatePacticipantNames.
15 16 17 18 |
# File 'lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb', line 15 def initialize new_name, existing_names @new_name = new_name @existing_names = existing_names end |
Instance Attribute Details
#existing_names ⇒ Object (readonly)
Returns the value of attribute existing_names.
13 14 15 |
# File 'lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb', line 13 def existing_names @existing_names end |
#new_name ⇒ Object (readonly)
Returns the value of attribute new_name.
13 14 15 |
# File 'lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb', line 13 def new_name @new_name end |
Class Method Details
.call(new_name, existing_names) ⇒ Object
20 21 22 |
# File 'lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb', line 20 def self.call new_name, existing_names new(new_name, existing_names).call end |
Instance Method Details
#call ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb', line 24 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
36 37 38 |
# File 'lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb', line 36 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
32 33 34 |
# File 'lib/pact_broker/functions/find_potential_duplicate_pacticipant_names.rb', line 32 def similar?(new_name, existing_name) existing_name.include?(new_name) || new_name.include?(existing_name) end |