Class: Task

Inherits:
Object
  • Object
show all
Defined in:
lib/task_manager.rb

Overview

Define a Task class to represent each task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, status = 'todo') ⇒ Task

Returns a new instance of Task.



9
10
11
12
13
14
15
# File 'lib/task_manager.rb', line 9

def initialize(description, status = 'todo')
  @id = nil
  @description = description
  @status = status
  @created_at = Time.now
  @updated_at = Time.now
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#updated_atObject

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

Instance Method Details

#to_hObject



23
24
25
26
27
28
29
30
31
# File 'lib/task_manager.rb', line 23

def to_h
  {
    id: @id,
    description: @description,
    status: @status,
    created_at: @created_at.to_s,
    updated_at: @updated_at.to_s
  }
end

#to_sObject



33
34
35
# File 'lib/task_manager.rb', line 33

def to_s
  "ID: #{@id} | Description: #{@description} | Status: #{@status} | Created At: #{@created_at} | Updated At: #{@updated_at}"
end

#update(description, status) ⇒ Object



17
18
19
20
21
# File 'lib/task_manager.rb', line 17

def update(description, status)
  @description = description
  @status = status
  @updated_at = Time.now
end