This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 6428d81c Make allowance for duplicate names
6428d81c is described below
commit 6428d81cf9648e28f0bafb976dd00f7ab3999625
Author: Sebb <[email protected]>
AuthorDate: Mon Jun 12 19:59:04 2023 +0100
Make allowance for duplicate names
---
lib/whimsy/asf/icla.rb | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/lib/whimsy/asf/icla.rb b/lib/whimsy/asf/icla.rb
index 21d1ec8e..4dc97ef7 100644
--- a/lib/whimsy/asf/icla.rb
+++ b/lib/whimsy/asf/icla.rb
@@ -103,16 +103,28 @@ module ASF
@@email_index[value.downcase]
end
- # find ICLA by name
- def self.find_by_name(value)
+ # find ICLA by (public) name
+ # There are multiple entries with the same name.
+ # So if there are multiple matches, it does not make sense to return a
single entry.
+ # By default, only return an entry if there is a single match. (else nil)
+ # If the multiple param is true, return an array of all matching entries.
+ # The array may be empty; does not return nil.
+ #
+ # N.B. matching by name is inherently inaccurate due to misspellings and
duplicates.
+ # There are likely to be both false positives and false negatives. Use
with caution!
+ def self.find_by_name(value, multiple=false)
return unless SOURCE
refresh
unless @@name_index
- @@name_index = {}
- each {|icla| @@name_index[icla.name] = icla}
+ # Collect all the entries for each matching name
+ @@name_index = Hash.new {|h, k| h[k] = Array.new}
+ each {|icla| @@name_index[icla.name] << icla }
end
- @@name_index[value]
+ entries = @@name_index[value]
+ return entries if multiple # no filtering needed
+ return entries.first if entries&.size == 1
+ return nil
end
# find number of matches in target array