Class: Worklog::Project
- Inherits:
-
Object
- Object
- Worklog::Project
- Defined in:
- lib/project.rb
Overview
Represents a project. A project is a longer running task or initiative. Single log entries can be associated with a project.
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Project
Creates a new Project instance from a hash of attributes.
Instance Method Summary collapse
-
#ended? ⇒ Boolean
Returns true if the project has ended, false otherwise.
-
#started? ⇒ Boolean
Returns true if the project has started, false otherwise.
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/project.rb', line 7 def description @description end |
#end_date ⇒ Object
Returns the value of attribute end_date.
7 8 9 |
# File 'lib/project.rb', line 7 def end_date @end_date end |
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/project.rb', line 7 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/project.rb', line 7 def name @name end |
#start_date ⇒ Object
Returns the value of attribute start_date.
7 8 9 |
# File 'lib/project.rb', line 7 def start_date @start_date end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/project.rb', line 7 def status @status end |
Class Method Details
.from_hash(hash) ⇒ Project
Creates a new Project instance from a hash of attributes.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/project.rb', line 18 def self.from_hash(hash) project = new # Ensure that at least the key is present raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key'] project.key = hash[:key] || hash['key'] project.name = hash[:name] || hash['name'] project.description = hash[:description] || hash['description'] project.start_date = hash[:start_date] || hash['start_date'] project.end_date = hash[:end_date] || hash['end_date'] project.status = hash[:status] || hash['status'] project end |
Instance Method Details
#ended? ⇒ Boolean
Returns true if the project has ended, false otherwise.
43 44 45 |
# File 'lib/project.rb', line 43 def ended? !end_date.nil? && end_date < Date.today end |
#started? ⇒ Boolean
Returns true if the project has started, false otherwise. A project is considered started if either
- its start date is nil or
- its start date is less than or equal to today's date.
37 38 39 |
# File 'lib/project.rb', line 37 def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end |