class Eco::API::Common::People::Entries::MultipleSearchResults
Error
class that allows to handle cases where multiple entries were found for the same criterion. @note its main purpose to prevent the false pairing 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<PersonEntry>] the entries that match the same search criterion. @param property [String] the property of the entry model that triggered the error (base of the search criterion).
Calls superclass method
# File lib/eco/api/common/people/entries.rb, line 15 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/common/people/entries.rb, line 31 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/common/people/entries.rb, line 23 def identify_candidates(with_index: false) candidates.map.each_with_index do |entry, i| index = with_index ? "#{i}. " : "" "#{index} #{entry.identify}" end end
Private Instance Methods
candidates_summary()
click to toggle source
# File lib/eco/api/common/people/entries.rb, line 37 def candidates_summary lines = ["The following entries have the same '#{property}':"] lines.concat(identify_candidates(with_index: true)).join("\n ") end