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

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/project.rb', line 7

def description
  @description
end

#end_dateObject

Returns the value of attribute end_date.



7
8
9
# File 'lib/project.rb', line 7

def end_date
  @end_date
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/project.rb', line 7

def key
  @key
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/project.rb', line 7

def name
  @name
end

#start_dateObject

Returns the value of attribute start_date.



7
8
9
# File 'lib/project.rb', line 7

def start_date
  @start_date
end

#statusObject

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.

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)


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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    true if the project has started, false otherwise



37
38
39
# File 'lib/project.rb', line 37

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