Exception: Eco::API::Organization::People::MultipleSearchResults

Inherits:
StandardError
  • Object
show all
Defined in:
lib/eco/api/organization/people/multiple_search_results.rb

Overview

Note:

its main purpose to prevent the creation of duplicates or override information between different people.

Error class that allows to handle cases where multiple people were found for the same criterion.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, candidates: [], property: 'email') ⇒ MultipleSearchResults

Returns a new instance of MultipleSearchResults.

Parameters:

  • msg (String)

    the basic message error.

  • candiates (Array<Person>)

    the people that match the same search criterion.

  • property (String) (defaults to: 'email')

    the property of the person model that triggered the error (base of the search criterion).



13
14
15
16
17
# File 'lib/eco/api/organization/people/multiple_search_results.rb', line 13

def initialize(msg, candidates: [], property: 'email')
  @candidates = candidates
  @property   = property
  super("#{msg} #{candidates_summary}")
end

Instance Attribute Details

#candidatesObject (readonly)

Returns the value of attribute candidates.



8
9
10
# File 'lib/eco/api/organization/people/multiple_search_results.rb', line 8

def candidates
  @candidates
end

#propertyObject (readonly)

Returns the value of attribute property.



8
9
10
# File 'lib/eco/api/organization/people/multiple_search_results.rb', line 8

def property
  @property
end

Instance Method Details

#candidate(index) ⇒ Person

Returns the candidate in the index position.

Returns:

  • (Person)

    the candidate in the index position



40
41
42
# File 'lib/eco/api/organization/people/multiple_search_results.rb', line 40

def candidate(index)
  candidates[index]
end

#first_userObject



19
20
21
# File 'lib/eco/api/organization/people/multiple_search_results.rb', line 19

def first_user
  candidates.detect(&:account)
end

#identify_candidates(with_index: false) ⇒ Array<String>

Returns the candidates identified.

Parameters:

  • with_index (Boolean) (defaults to: false)

    to add an index to each candidate description.

Returns:

  • (Array<String>)

    the candidates identified



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/eco/api/organization/people/multiple_search_results.rb', line 25

def identify_candidates(with_index: false)
  candidates.map.each_with_index do |person, i|
    index = with_index ? "#{i}. " : ''

    msg = '(no account)'
    if person.
      msg = '(user)'
      msg = '(new user)' if person.
    end

    "#{index}#{msg} #{person.identify}"
  end
end