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.



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

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.



6
7
8
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 6

def existing_names
  @existing_names
end

#new_nameObject (readonly)

Returns the value of attribute new_name.



6
7
8
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 6

def new_name
  @new_name
end

Class Method Details

.call(new_name, existing_names) ⇒ Object



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

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

.split(string) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 29

def self.split(string)
  string.gsub(/\s/, "_")
        .gsub(/::/, "/")
        .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
        .gsub(/([a-z\d])([A-Z])/, '\1_\2')
        .tr("-", "_")
        .downcase
        .split("_")
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 17

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

  existing_names.select do | existing_name |
    clean(new_name) == clean(existing_name)
  end
end

#clean(name) ⇒ Object



25
26
27
# File 'lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names.rb', line 25

def clean(name)
  self.class.split(name).collect{|w| w.chomp("s") } - ["api", "provider", "service"]
end