Class: GitPair::Author
- Inherits:
-
Object
show all
- Defined in:
- lib/git-pair/author.rb
Defined Under Namespace
Classes: InvalidAuthorString
Constant Summary
collapse
- ValidAuthorStringRegex =
/^\s*([^<]+)<([^>]+)>\s*$/
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(string) ⇒ Author
Returns a new instance of Author.
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
53
54
55
|
# File 'lib/git-pair/author.rb', line 53
def email
@email
end
|
#name ⇒ Object
Returns the value of attribute name.
53
54
55
|
# File 'lib/git-pair/author.rb', line 53
def name
@name
end
|
Class Method Details
.domain_for(email_address) ⇒ Object
36
37
38
39
|
# File 'lib/git-pair/author.rb', line 36
def self.domain_for(email_address)
return pair_email.domain if pair_email.domain
return email_address.domain
end
|
.email_address_for(authors) ⇒ Object
22
23
24
|
# File 'lib/git-pair/author.rb', line 22
def self.email_address_for(authors)
"#{local_part_for(authors)}@#{domain_for(authors.first.email)}"
end
|
.exists?(author) ⇒ Boolean
41
42
43
|
# File 'lib/git-pair/author.rb', line 41
def self.exists?(author)
self.all.find { |a| a.name == author.name }
end
|
.find(abbr) ⇒ Object
17
18
19
20
|
# File 'lib/git-pair/author.rb', line 17
def self.find(abbr)
all.find { |author| author.match?(abbr) } ||
raise(NoMatchingAuthorsError, "no authors matched #{abbr}")
end
|
.find_all(abbrs) ⇒ Object
12
13
14
15
|
# File 'lib/git-pair/author.rb', line 12
def self.find_all(abbrs)
raise MissingConfigurationError, "Please add some authors first" if all.empty?
abbrs.map { |abbr| self.find(abbr) }
end
|
.local_part_for(authors) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/git-pair/author.rb', line 26
def self.local_part_for(authors)
return authors.first.email.local_part if authors.size == 1
if pair_email.local_part && pair_email.local_part != ""
authors.map(&:initials).unshift(pair_email.local_part).join("+")
else
authors.map { |author| author.email.local_part }.join("+")
end
end
|
.valid_string?(author_string) ⇒ Boolean
45
46
47
|
# File 'lib/git-pair/author.rb', line 45
def self.valid_string?(author_string)
author_string =~ ValidAuthorStringRegex
end
|
Instance Method Details
#<=>(other) ⇒ Object
65
66
67
|
# File 'lib/git-pair/author.rb', line 65
def <=>(other)
name.split.last <=> other.name.split.last
end
|
#initials ⇒ Object
69
70
71
|
# File 'lib/git-pair/author.rb', line 69
def initials
name.split.map { |word| word[0].chr }.join.downcase
end
|
#match?(abbr) ⇒ Boolean
73
74
75
|
# File 'lib/git-pair/author.rb', line 73
def match?(abbr)
abbr.downcase == initials
end
|