Class: Mailmap::Map
Overview
A Map represents a .mailmap file.
Class Method Summary collapse
-
.load(path) ⇒ Map
Load a mailmap file and return Map object.
Instance Method Summary collapse
- #each ⇒ Object
-
#include_email?(email) ⇒ Boolean
Return true if the email is defined as either of proper or commit email, otherwise false.
-
#include_name?(name) ⇒ Boolean
Return true if the name is defined as either of proper or commit name, otherwise false.
-
#initialize(string) ⇒ Map
constructor
A new instance of Map.
-
#lookup(commit_name_or_nil, commit_email) ⇒ (String, String), ...
Look up the person’s canonical name and email address.
-
#resolve(commit_name_or_nil, commit_email) ⇒ (String, String), (nil, String)
Like
git-check-mailmap
command, look up the person’s canonical name and email address.
Constructor Details
#initialize(string) ⇒ Map
Returns a new instance of Map.
27 28 29 30 31 |
# File 'lib/mailmap/map.rb', line 27 def initialize(string) # @type ivar @map: Hash[String, Hash[String?, String?]] @map = Hash.new { |h, k| h[k] = {} } parse(string) end |
Class Method Details
.load(path) ⇒ Map
Load a mailmap file and return Map object.
19 20 21 |
# File 'lib/mailmap/map.rb', line 19 def load(path) new(File.read(path)) end |
Instance Method Details
#each ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mailmap/map.rb', line 33 def each return enum_for unless block_given? @map.each do |commit_email, entries_by_commit_name| entries_by_commit_name.each do |commit_name, (proper_name, proper_email)| yield proper_name, proper_email, commit_name, commit_email end end self end |
#include_email?(email) ⇒ Boolean
Return true if the email is defined as either of proper or commit email, otherwise false. The comparison is case-insensitive.
91 92 93 94 95 96 |
# File 'lib/mailmap/map.rb', line 91 def include_email?(email) email = email.downcase any? do |_proper_name, proper_email, _commit_name, commit_email| proper_email&.downcase == email || commit_email == email end end |
#include_name?(name) ⇒ Boolean
Return true if the name is defined as either of proper or commit name, otherwise false. The comparison is case-insensitive.
79 80 81 82 83 84 |
# File 'lib/mailmap/map.rb', line 79 def include_name?(name) name = name.downcase any? do |proper_name, _proper_email, commit_name, _commit_email| proper_name&.downcase == name || commit_name == name end end |
#lookup(commit_name_or_nil, commit_email) ⇒ (String, String), ...
Look up the person’s canonical name and email address. If found, return them; otherwise return nil.
53 54 55 56 57 58 |
# File 'lib/mailmap/map.rb', line 53 def lookup(commit_name_or_nil, commit_email) commit_name = commit_name_or_nil&.downcase commit_email = commit_email.downcase hash = @map[commit_email] hash[commit_name] || hash[nil] end |
#resolve(commit_name_or_nil, commit_email) ⇒ (String, String), (nil, String)
Like git-check-mailmap
command, look up the person’s canonical name and email address. If found, return them; otherwise return the input as-is.
67 68 69 70 71 72 |
# File 'lib/mailmap/map.rb', line 67 def resolve(commit_name_or_nil, commit_email) proper_name, proper_email = lookup(commit_name_or_nil, commit_email) proper_name ||= commit_name_or_nil proper_email ||= commit_email [proper_name, proper_email] end |