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.
37
38
39
|
# File 'lib/git-pair/author.rb', line 37
def email
@email
end
|
#name ⇒ Object
Returns the value of attribute name.
37
38
39
|
# File 'lib/git-pair/author.rb', line 37
def name
@name
end
|
Class Method Details
.email(authors) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/git-pair/author.rb', line 21
def self.email(authors)
if authors.length == 1
authors.first.email
else
Config.default_email
end
end
|
.exists?(author) ⇒ Boolean
29
30
31
|
# File 'lib/git-pair/author.rb', line 29
def self.exists?(author)
self.all.find { |a| a.name == author.name }
end
|
.find(abbr) ⇒ Object
16
17
18
19
|
# File 'lib/git-pair/author.rb', line 16
def self.find(abbr)
all.find { |author| author.match?(abbr) } ||
raise(NoMatchingAuthorsError, "no authors matched #{abbr}")
end
|
.find_all(abbrs) ⇒ Object
11
12
13
14
|
# File 'lib/git-pair/author.rb', line 11
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
33
34
35
|
# File 'lib/git-pair/author.rb', line 33
def self.valid_string?(author_string)
author_string =~ ValidAuthorStringRegex
end
|
Instance Method Details
#<=>(other) ⇒ Object
49
50
51
|
# File 'lib/git-pair/author.rb', line 49
def <=>(other)
name.split.last <=> other.name.split.last
end
|
#initials ⇒ Object
53
54
55
|
# File 'lib/git-pair/author.rb', line 53
def initials
name.split.map { |word| word[0].chr }.join.downcase
end
|
#match?(abbr) ⇒ Boolean
57
58
59
|
# File 'lib/git-pair/author.rb', line 57
def match?(abbr)
abbr.downcase == initials
end
|