Class: Gas::User
- Inherits:
-
Object
- Object
- Gas::User
- Defined in:
- lib/gas/user.rb
Overview
Class that contains data for a git user
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
Instance Method Summary collapse
-
#==(user) ⇒ boolean
Define the equality operator to test if two user objects are the same.
-
#git_user ⇒ String
Returns the git format of user.
-
#initialize(name, email, nickname = '') ⇒ User
constructor
A new instance of User.
-
#to_s(use_nickname = true) ⇒ String
Overides to_s to output in the correct format.
Constructor Details
#initialize(name, email, nickname = '') ⇒ User
Returns a new instance of User.
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
#email ⇒ Object (readonly)
Returns the value of attribute email.
5 6 7 |
# File 'lib/gas/user.rb', line 5 def email @email end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/gas/user.rb', line 5 def name @name end |
#nickname ⇒ Object (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
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_user ⇒ String
Returns the git format of user
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
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 |