Class: Worklog::Person
- Inherits:
-
Object
- Object
- Worklog::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
!attribute [r] inactive
@return [Boolean] Whether the person is inactive (for example left the company)
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#github_username ⇒ Object
readonly
Returns the value of attribute github_username.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#inactive ⇒ Object
readonly
Returns the value of attribute inactive.
-
#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
-
#active? ⇒ Boolean
Returns true if the person is active (not inactive).
-
#inactive? ⇒ Boolean
Returns true if the person is marked as inactive.
-
#initialize(handle:, name:, **params) ⇒ Person
constructor
A new instance of Person.
- #to_s ⇒ Object
Constructor Details
#initialize(handle:, name:, **params) ⇒ Person
Returns a new instance of Person.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/person.rb', line 21 def initialize(handle:, name:, **params) # params to symbol keys params = params.transform_keys(&:to_sym) @handle = handle @name = name @github_username = params[:github_username] @email = params[:email] @team = params[:team] @notes = params[:notes] || [] @inactive = params[:inactive] || false end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
19 20 21 |
# File 'lib/person.rb', line 19 def email @email end |
#github_username ⇒ Object (readonly)
Returns the value of attribute github_username.
19 20 21 |
# File 'lib/person.rb', line 19 def github_username @github_username end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
19 20 21 |
# File 'lib/person.rb', line 19 def handle @handle end |
#inactive ⇒ Object (readonly)
Returns the value of attribute inactive.
19 20 21 |
# File 'lib/person.rb', line 19 def inactive @inactive end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/person.rb', line 19 def name @name end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
19 20 21 |
# File 'lib/person.rb', line 19 def notes @notes end |
#team ⇒ Object (readonly)
Returns the value of attribute team.
19 20 21 |
# File 'lib/person.rb', line 19 def team @team end |
Class Method Details
.from_hash(hash) ⇒ Person
Creates a new Person instance from a hash of attributes.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/person.rb', line 55 def self.from_hash(hash) hash = hash.transform_keys(&:to_sym) raise ArgumentError, 'Person handle is required' unless hash[:handle] raise ArgumentError, 'Person name is required' unless hash[:name] handle = hash[:handle] name = hash[:name] Person.new(handle: handle, name: name, **hash) end |
Instance Method Details
#==(other) ⇒ Object
72 73 74 75 76 |
# File 'lib/person.rb', line 72 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 |
#active? ⇒ Boolean
Returns true if the person is active (not inactive). If not specified, persons are active by default.
37 38 39 |
# File 'lib/person.rb', line 37 def active? !@inactive end |
#inactive? ⇒ Boolean
Returns true if the person is marked as inactive.
43 44 45 |
# File 'lib/person.rb', line 43 def inactive? @inactive end |
#to_s ⇒ Object
66 67 68 69 70 |
# File 'lib/person.rb', line 66 def to_s return "#{name} (~#{handle})" if @email.nil? "#{name} (~#{handle}) <#{email}>" end |