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.
-
#entries ⇒ Array<LogEntry>
These entries are related to the work done on this project.
-
#key ⇒ String
Unique identifier for the project, used in log entries.
-
#last_activity ⇒ Date?
The last activity is not stored in the project itself.
-
#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.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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 |
#entries ⇒ Array<LogEntry>
These entries are related to the work done on this project. Entries are populated dynamically when processing daily logs. They are not stored in the project itself.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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?
The last activity is not stored in the project itself. Instead, it is updated dynamically when processing daily logs. It represents the most recent log entry time for this project.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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.
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 63 64 65 66 67 68 69 70 |
# File 'lib/project.rb', line 30 class Project attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :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.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/project.rb', line 42 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.
67 68 69 |
# File 'lib/project.rb', line 67 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.
61 62 63 |
# File 'lib/project.rb', line 61 def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end |