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_or_name) ⇒ Object
17
18
19
20
|
# File 'lib/git-pair/author.rb', line 17
def self.find(abbr_or_name)
all.find { |author| author.match?(abbr_or_name) } ||
raise(NoMatchingAuthorsError, "no authors matched #{abbr_or_name}")
end
|
.find_all(abbrs_or_names) ⇒ Object
12
13
14
15
|
# File 'lib/git-pair/author.rb', line 12
def self.find_all(abbrs_or_names)
raise MissingConfigurationError, "Please add some authors first" if all.empty?
abbrs_or_names.map { |abbr_or_name| self.find(abbr_or_name) }
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)
first_name <=> other.first_name
end
|
#first_name ⇒ Object
59
60
61
|
# File 'lib/git-pair/author.rb', line 59
def first_name
name.split.first.downcase
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
|
#last_name ⇒ Object
63
64
65
|
# File 'lib/git-pair/author.rb', line 63
def last_name
name.split.last.downcase
end
|
#match?(abbr_or_name) ⇒ Boolean
67
68
69
|
# File 'lib/git-pair/author.rb', line 67
def match?(abbr_or_name)
abbr_or_name.downcase == first_name || abbr_or_name.downcase == last_name || abbr_or_name.downcase == initials
end
|