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 ⇒ String?
A description of the project, can be nil.
-
#end_date ⇒ Date?
The end date of the project, can be nil.
-
#key ⇒ String
Unique identifier for the project, used in log entries.
-
#last_activity ⇒ Date?
The last activity date or nil if not set.
-
#name ⇒ String
The human-readable name of the project.
-
#start_date ⇒ Date?
The start date of the project, can be nil.
-
#status ⇒ String?
Possible values: ‘active’, ‘completed’, ‘archived’, etc.
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 ⇒ String?
Returns A description of the project, can be nil.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project.rb', line 22 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity # Creates a new Project instance from a hash of attributes. # @param hash [Hash] A hash containing project attributes # @option hash [String] :key The project key # @option hash [String] :name The project name # @option hash [String] :description The project description # @option hash [Date] :start_date The project start date # @option hash [Date] :end_date The project end date # @option hash [String] :status The project status # @return [Project] A new Project instance 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 # 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. # @return [Boolean] true if the project has started, false otherwise def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end # Returns true if the project has ended, false otherwise. # @return [Boolean] true if the project has ended, false otherwise def ended? !end_date.nil? && end_date < Date.today end end |
#end_date ⇒ Date?
Returns The end date of the project, can be nil.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project.rb', line 22 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity # Creates a new Project instance from a hash of attributes. # @param hash [Hash] A hash containing project attributes # @option hash [String] :key The project key # @option hash [String] :name The project name # @option hash [String] :description The project description # @option hash [Date] :start_date The project start date # @option hash [Date] :end_date The project end date # @option hash [String] :status The project status # @return [Project] A new Project instance 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 # 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. # @return [Boolean] true if the project has started, false otherwise def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end # Returns true if the project has ended, false otherwise. # @return [Boolean] true if the project has ended, false otherwise def ended? !end_date.nil? && end_date < Date.today end end |
#key ⇒ String
Returns Unique identifier for the project, used in log entries.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project.rb', line 22 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity # Creates a new Project instance from a hash of attributes. # @param hash [Hash] A hash containing project attributes # @option hash [String] :key The project key # @option hash [String] :name The project name # @option hash [String] :description The project description # @option hash [Date] :start_date The project start date # @option hash [Date] :end_date The project end date # @option hash [String] :status The project status # @return [Project] A new Project instance 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 # 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. # @return [Boolean] true if the project has started, false otherwise def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end # Returns true if the project has ended, false otherwise. # @return [Boolean] true if the project has ended, false otherwise def ended? !end_date.nil? && end_date < Date.today end end |
#last_activity ⇒ Date?
Returns The last activity date or nil if not set.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project.rb', line 22 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity # Creates a new Project instance from a hash of attributes. # @param hash [Hash] A hash containing project attributes # @option hash [String] :key The project key # @option hash [String] :name The project name # @option hash [String] :description The project description # @option hash [Date] :start_date The project start date # @option hash [Date] :end_date The project end date # @option hash [String] :status The project status # @return [Project] A new Project instance 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 # 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. # @return [Boolean] true if the project has started, false otherwise def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end # Returns true if the project has ended, false otherwise. # @return [Boolean] true if the project has ended, false otherwise def ended? !end_date.nil? && end_date < Date.today end end |
#name ⇒ String
Returns The human-readable name of the project.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project.rb', line 22 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity # Creates a new Project instance from a hash of attributes. # @param hash [Hash] A hash containing project attributes # @option hash [String] :key The project key # @option hash [String] :name The project name # @option hash [String] :description The project description # @option hash [Date] :start_date The project start date # @option hash [Date] :end_date The project end date # @option hash [String] :status The project status # @return [Project] A new Project instance 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 # 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. # @return [Boolean] true if the project has started, false otherwise def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end # Returns true if the project has ended, false otherwise. # @return [Boolean] true if the project has ended, false otherwise def ended? !end_date.nil? && end_date < Date.today end end |
#start_date ⇒ Date?
Returns The start date of the project, can be nil.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project.rb', line 22 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity # Creates a new Project instance from a hash of attributes. # @param hash [Hash] A hash containing project attributes # @option hash [String] :key The project key # @option hash [String] :name The project name # @option hash [String] :description The project description # @option hash [Date] :start_date The project start date # @option hash [Date] :end_date The project end date # @option hash [String] :status The project status # @return [Project] A new Project instance 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 # 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. # @return [Boolean] true if the project has started, false otherwise def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end # Returns true if the project has ended, false otherwise. # @return [Boolean] true if the project has ended, false otherwise def ended? !end_date.nil? && end_date < Date.today end end |
#status ⇒ String?
Possible values: ‘active’, ‘completed’, ‘archived’, etc. Indicates the current state of the project.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/project.rb', line 22 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :last_activity # Creates a new Project instance from a hash of attributes. # @param hash [Hash] A hash containing project attributes # @option hash [String] :key The project key # @option hash [String] :name The project name # @option hash [String] :description The project description # @option hash [Date] :start_date The project start date # @option hash [Date] :end_date The project end date # @option hash [String] :status The project status # @return [Project] A new Project instance 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 # 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. # @return [Boolean] true if the project has started, false otherwise def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end # Returns true if the project has ended, false otherwise. # @return [Boolean] true if the project has ended, false otherwise def ended? !end_date.nil? && end_date < Date.today end end |
Class Method Details
.from_hash(hash) ⇒ Project
Creates a new Project instance from a hash of attributes.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/project.rb', line 34 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.
59 60 61 |
# File 'lib/project.rb', line 59 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.
53 54 55 |
# File 'lib/project.rb', line 53 def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end |