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.
39
40
41
|
# File 'lib/git-pair/author.rb', line 39
def email
@email
end
|
#name ⇒ Object
Returns the value of attribute name.
39
40
41
|
# File 'lib/git-pair/author.rb', line 39
def name
@name
end
|
Class Method Details
.email(authors) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/git-pair/author.rb', line 22
def self.email(authors)
if authors.length == 1
authors.first.email
else
initials_string = '+' + authors.map { |a| a.initials }.join('+')
Config.default_email.sub("@", "#{initials_string}@")
end
end
|
.exists?(author) ⇒ Boolean
31
32
33
|
# File 'lib/git-pair/author.rb', line 31
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
|
.valid_string?(author_string) ⇒ Boolean
35
36
37
|
# File 'lib/git-pair/author.rb', line 35
def self.valid_string?(author_string)
author_string =~ ValidAuthorStringRegex
end
|
Instance Method Details
#<=>(other) ⇒ Object
51
52
53
|
# File 'lib/git-pair/author.rb', line 51
def <=>(other)
name.split.last <=> other.name.split.last
end
|
#initials ⇒ Object
55
56
57
|
# File 'lib/git-pair/author.rb', line 55
def initials
name.split.map { |word| word[0].chr }.join.downcase
end
|
#match?(abbr) ⇒ Boolean
59
60
61
|
# File 'lib/git-pair/author.rb', line 59
def match?(abbr)
abbr.downcase == initials
end
|