Class: KhoinguyenEhTodoList::Task

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

Overview

Represents a task in the todo list

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Task

Returns a new instance of Task.



8
9
10
11
# File 'lib/khoinguyen_eh_todo_list/task.rb', line 8

def initialize(title)
  @title = title
  @completed = false
end

Instance Attribute Details

#completed ⇒ Object

Returns the value of attribute completed.



6
7
8
# File 'lib/khoinguyen_eh_todo_list/task.rb', line 6

def completed
  @completed
end

#title ⇒ Object

Returns the value of attribute title.



6
7
8
# File 'lib/khoinguyen_eh_todo_list/task.rb', line 6

def title
  @title
end

Instance Method Details

#completed? ⇒ Boolean

Returns the completion status

Returns:

  • (Boolean)


20
21
22
# File 'lib/khoinguyen_eh_todo_list/task.rb', line 20

def completed?
  @completed
end

#to_s ⇒ Object



24
25
26
27
# File 'lib/khoinguyen_eh_todo_list/task.rb', line 24

def to_s
  status = @completed ? "[X]" : "[ ]"
  "#{status} #{@title}"
end

#toggle_completion ⇒ Object

Toggles the completion status of the task



14
15
16
# File 'lib/khoinguyen_eh_todo_list/task.rb', line 14

def toggle_completion
  @completed = !@completed
end