Class: GitSu::User
- Inherits:
-
Object
- Object
- GitSu::User
- Defined in:
- lib/gitsu/user.rb
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- NONE =
User.new(nil, nil)
Instance Attribute Summary collapse
-
#emails ⇒ Object
writeonly
Sets the attribute emails.
-
#names ⇒ Object
writeonly
Sets the attribute names.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #clone ⇒ Object
- #combine(other, group_email) ⇒ Object
- #email ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, email) ⇒ User
constructor
A new instance of User.
- #initials ⇒ Object
- #name ⇒ Object
- #none? ⇒ Boolean
- #to_ansi_s(name_color, email_color, reset_color) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, email) ⇒ User
Returns a new instance of User.
27 28 29 |
# File 'lib/gitsu/user.rb', line 27 def initialize(name, email) @names, @emails = [name], [email] end |
Instance Attribute Details
#emails=(value) ⇒ Object
Sets the attribute emails
24 25 26 |
# File 'lib/gitsu/user.rb', line 24 def emails=(value) @emails = value end |
#names=(value) ⇒ Object
Sets the attribute names
24 25 26 |
# File 'lib/gitsu/user.rb', line 24 def names=(value) @names = value end |
Class Method Details
.parse(string) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gitsu/user.rb', line 39 def User.parse(string) fully_qualified_user_regex = /^[^<]+<[^>]+>$/ if string =~ fully_qualified_user_regex name = string[/^[^<]+/].strip email = string[/<.*>/].delete "[<>]" User.new(name, email) else raise ParseError, "Couldn't parse '#{string}' as user (expected user in format: 'John Smith <[email protected]>')" end end |
Instance Method Details
#==(other) ⇒ Object
93 94 95 |
# File 'lib/gitsu/user.rb', line 93 def ==(other) eql? other end |
#clone ⇒ Object
60 61 62 63 64 65 |
# File 'lib/gitsu/user.rb', line 60 def clone deep_clone = super deep_clone.names = names.clone deep_clone.emails = emails.clone deep_clone end |
#combine(other, group_email) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/gitsu/user.rb', line 50 def combine(other, group_email) if none? other elsif other.none? self else clone.combine! other, group_email end end |
#email ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gitsu/user.rb', line 72 def email emails = emails_and_names.map {|email,name| email} if emails.size == 1 emails.first else email_prefixes = emails.map { |email| email.sub /@.*/, '' } email_domain = emails.first.sub /^.*@/, '' group_email_prefix = @group_email.sub /@.*/, '' group_email_domain = @group_email.sub /^.*@/, '' group_email_prefix + '+' + email_prefixes.join('+') + '@' + group_email_domain end end |
#eql?(other) ⇒ Boolean
97 98 99 |
# File 'lib/gitsu/user.rb', line 97 def eql?(other) name == other.name && email == other.email end |
#hash ⇒ Object
101 102 103 |
# File 'lib/gitsu/user.rb', line 101 def hash to_s.hash end |
#initials ⇒ Object
85 86 87 |
# File 'lib/gitsu/user.rb', line 85 def initials names.join(" ").split(" ").map { |word| word.chars.first }.join.downcase end |
#name ⇒ Object
67 68 69 70 |
# File 'lib/gitsu/user.rb', line 67 def name names = emails_and_names.map {|email,name| name} names.to_sentence end |
#to_ansi_s(name_color, email_color, reset_color) ⇒ Object
105 106 107 |
# File 'lib/gitsu/user.rb', line 105 def to_ansi_s(name_color, email_color, reset_color) "#{name_color}#{name}#{reset_color} #{email_color}<#{email}>#{reset_color}" end |
#to_s ⇒ Object
109 110 111 |
# File 'lib/gitsu/user.rb', line 109 def to_s to_ansi_s("", "", "") end |