Class: Gas::User

Inherits:
Object
  • Object
show all
Defined in:
lib/gas/user.rb

Overview

Class that contains data for a git user

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, email, nickname = '') ⇒ User

Returns a new instance of User.

Parameters:

  • name (String)

    The name of the user

  • email (String)

    The email of the user

  • nickname (String) (defaults to: '')

    A nickname for the user, not used when parsing from gitconfig



10
11
12
13
14
# File 'lib/gas/user.rb', line 10

def initialize(name, email, nickname = '')
  @name = name
  @email = email
  @nickname = nickname
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/gas/user.rb', line 5

def email
  @email
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gas/user.rb', line 5

def name
  @name
end

#nicknameObject (readonly)

Returns the value of attribute nickname.



5
6
7
# File 'lib/gas/user.rb', line 5

def nickname
  @nickname
end

Instance Method Details

#==(user) ⇒ boolean

Define the equality operator to test if two user objects are the same

Parameters:

  • the (Object)

    object to test against

Returns:

  • (boolean)


32
33
34
35
36
37
38
# File 'lib/gas/user.rb', line 32

def ==(user)
  return false unless user.is_a? User
  unless nickname.empty? || user.nickname.empty? # Don't test equallity in nickname if any of the nicknames is not used
    return false unless nickname == user.nickname
  end
  return (name == user.name && email == user.email)
end

#git_userString

Returns the git format of user

Returns:

  • (String)


18
19
20
# File 'lib/gas/user.rb', line 18

def git_user
  to_s false
end

#to_s(use_nickname = true) ⇒ String

Overides to_s to output in the correct format

Parameters:

  • use_nickname (Boolean) (defaults to: true)

    Defaults to true

Returns:

  • (String)


25
26
27
# File 'lib/gas/user.rb', line 25

def to_s(use_nickname = true)
  "      [#{use_nickname ? @nickname : 'user'}]\n         name = #{@name}\n         email = #{@email}"
end