class GitSu::User

Constants

NONE

Attributes

emails[RW]
names[RW]

Public Class Methods

new(name, email) click to toggle source
# File lib/gitsu/user.rb, line 27
def initialize(name, email)
    @names, @emails = [name], [email]
end
parse(string) click to toggle source
# 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 <jsmith@example.com>')"
    end
end

Public Instance Methods

==(other) click to toggle source
# File lib/gitsu/user.rb, line 93
def ==(other)
    eql? other
end
clone() click to toggle source
Calls superclass method
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/gitsu/user.rb, line 97
def eql?(other)
    name == other.name && email == other.email
end
hash() click to toggle source
# File lib/gitsu/user.rb, line 101
def hash
    to_s.hash
end
initials() click to toggle source
# File lib/gitsu/user.rb, line 85
def initials
    names.join(" ").split(" ").map { |word| word.chars.first }.join.downcase
end
name() click to toggle source
# File lib/gitsu/user.rb, line 67
def name
    names = emails_and_names.map {|email,name| name}
    names.to_sentence
end
none?() click to toggle source
# File lib/gitsu/user.rb, line 89
def none?
    self === NONE
end
to_ansi_s(name_color, email_color, reset_color) click to toggle source
# 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() click to toggle source
# File lib/gitsu/user.rb, line 109
def to_s
    to_ansi_s("", "", "")
end

Protected Instance Methods

combine!(other, group_email) click to toggle source
# File lib/gitsu/user.rb, line 114
def combine!(other, group_email)
    @names += other.names
    @emails += other.emails
    @group_email = group_email
    self
end

Private Instance Methods

emails_and_names() click to toggle source

Array of emails and names, unique and ordered

# File lib/gitsu/user.rb, line 123
def emails_and_names
    combined = @emails.zip @names
    Hash[combined].sort 
end