Class: Person
- Inherits:
-
Object
- Object
- Person
- Defined in:
- lib/person.rb
Overview
Represents a person at work.
!attribute [r] handle
@return [String] The person's handle (username)
!attribute [r] name
@return [String] The person's full name
!attribute [r] email
@return [String, nil] The person's email address, can be nil
!attribute [r] team
@return [String, nil] The team the person belongs to, can be nil
!attribute [r] notes
@return [Array<String>] An array of notes about the person
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#team ⇒ Object
readonly
Returns the value of attribute team.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Person
Creates a new Person instance from a hash of attributes.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(handle, name, email, team, notes = []) ⇒ Person
constructor
A new instance of Person.
- #to_s ⇒ Object
Constructor Details
#initialize(handle, name, email, team, notes = []) ⇒ Person
Returns a new instance of Person.
18 19 20 21 22 23 24 |
# File 'lib/person.rb', line 18 def initialize(handle, name, email, team, notes = []) @handle = handle @name = name @email = email @team = team @notes = notes end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
16 17 18 |
# File 'lib/person.rb', line 16 def email @email end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
16 17 18 |
# File 'lib/person.rb', line 16 def handle @handle end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/person.rb', line 16 def name @name end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
16 17 18 |
# File 'lib/person.rb', line 16 def notes @notes end |
#team ⇒ Object (readonly)
Returns the value of attribute team.
16 17 18 |
# File 'lib/person.rb', line 16 def team @team end |
Class Method Details
.from_hash(hash) ⇒ Person
Creates a new Person instance from a hash of attributes.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/person.rb', line 34 def self.from_hash(hash) raise ArgumentError, 'Person handle is required' unless hash[:handle] || hash['handle'] raise ArgumentError, 'Person name is required' unless hash[:name] || hash['name'] handle = hash[:handle] || hash['handle'] name = hash[:name] || hash['name'] email = hash[:email] || hash['email'] team = hash[:team] || hash['team'] notes = hash[:notes] || hash['notes'] || [] Person.new(handle, name, email, team, notes) end |
Instance Method Details
#==(other) ⇒ Object
52 53 54 55 56 |
# File 'lib/person.rb', line 52 def ==(other) return false unless other.is_a?(Person) handle == other.handle && name == other.name && email == other.email && team == other.team && notes == other.notes end |
#to_s ⇒ Object
46 47 48 49 50 |
# File 'lib/person.rb', line 46 def to_s return "#{name} (~#{handle})" if @email.nil? "#{name} (~#{handle}) <#{email}>" end |