Class: Worklog::Project

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionString?

Returns A description of the project, can be nil.

Returns:

  • (String, nil)

    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_dateDate?

Returns The end date of the project, can be nil.

Returns:

  • (Date, nil)

    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

#entriesArray<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.

Returns:

  • (Array<LogEntry>)

    An array of log entries associated with 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

#keyString

Returns Unique identifier for the project, used in log entries.

Returns:

  • (String)

    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_activityDate?

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.

Returns:

  • (Date, nil)

    The last activity date or nil if not set.



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

#nameString

Returns The human-readable name of the project.

Returns:

  • (String)

    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_dateDate?

Returns The start date of the project, can be nil.

Returns:

  • (Date, nil)

    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

#statusString?

Possible values: ‘active’, ‘completed’, ‘archived’, etc. Indicates the current state of the project.

Returns:

  • (String, nil)

    The status 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

Class Method Details

.from_hash(hash) ⇒ Project

Creates a new Project instance from a hash of attributes.

Parameters:

  • hash (Hash)

    A hash containing project attributes

Options Hash (hash):

  • :key (String)

    The project key

  • :name (String)

    The project name

  • :description (String)

    The project description

  • :start_date (Date)

    The project start date

  • :end_date (Date)

    The project end date

  • :status (String)

    The project status

Returns:

  • (Project)

    A new Project instance

Raises:

  • (ArgumentError)


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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    true if the project has started, false otherwise



61
62
63
# File 'lib/project.rb', line 61

def started?
  start_date.nil? || (!start_date.nil? && start_date <= Date.today)
end