class Eco::API::Organization::People::MultipleSearchResults
Error
class that allows to handle cases where multiple people were found for the same criterion. @note its main purpose to prevent the creation of duplicates or override information between different people.
Attributes
candidates[R]
property[R]
Public Class Methods
new(msg, candidates: [], property: "email")
click to toggle source
@param msg [String] the basic message error. @param candiates [Array<Person>] the people that match the same search criterion. @param property [String] the property of the person model that triggered the error (base of the search criterion).
Calls superclass method
# File lib/eco/api/organization/people.rb, line 12 def initialize(msg, candidates: [], property: "email") @candidates = candidates @property = property super(msg + " " + candidates_summary) end
Public Instance Methods
candidate(index)
click to toggle source
@return [Person] the `candidate` in the `index` position
# File lib/eco/api/organization/people.rb, line 29 def candidate(index) candidates[index] end
identify_candidates(with_index: false)
click to toggle source
@param with_index [Boolean] to add an index to each candidate description. @return [Array<String>] the `candidates` identified
# File lib/eco/api/organization/people.rb, line 20 def identify_candidates(with_index: false) candidates.map.each_with_index do |person, i| index = with_index ? "#{i}. " : "" msg = person.account ? (person.account_added? ? "(new user)" : "(user)") : "(no account)" "#{index}#{msg} #{person.identify}" end end
Private Instance Methods
candidates_summary()
click to toggle source
# File lib/eco/api/organization/people.rb, line 35 def candidates_summary lines = ["The following people have the same '#{property}':"] lines.concat(identify_candidates(with_index: true)).join("\n ") end