Class: TodoList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTodoList

Returns a new instance of TodoList.



4
5
6
# File 'lib/todo_list.rb', line 4

def initialize
  @todo = {}
end

Instance Attribute Details

#todoObject (readonly)

Returns the value of attribute todo.



2
3
4
# File 'lib/todo_list.rb', line 2

def todo
  @todo
end

Instance Method Details

#add(todo) ⇒ Object



8
9
10
# File 'lib/todo_list.rb', line 8

def add(todo)
  @todo.store(todo.id, todo)
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/todo_list.rb', line 24

def empty?
  @todo.length == 0
end

#find(search) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/todo_list.rb', line 12

def find(search)
  list = TodoList.new
  @todo.each do |id, todo|
    list.add todo if /^#{search}/.match id
  end
  list
end

#lengthObject



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

def length
  @todo.length
end

#to_arrayObject



33
34
35
36
37
# File 'lib/todo_list.rb', line 33

def to_array
  todos = []
  @todo.each do |id, todo| todos << todo end
  todos
end

#update(todo) ⇒ Object



28
29
30
31
# File 'lib/todo_list.rb', line 28

def update(todo)
  @todo.delete(todo.id)
  @todo[todo.id] = todo
end