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



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

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

Returns:

  • (Date, nil)

    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

#keyString

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

Returns:

  • (String)

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

Returns The last activity date or nil if not set.

Returns:

  • (Date, nil)

    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

#nameString

Returns The human-readable name of the project.

Returns:

  • (String)

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

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

Returns:

  • (Date, nil)

    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

#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



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.

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)


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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    true if the project has started, false otherwise



53
54
55
# File 'lib/project.rb', line 53

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