-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_controller.rb
More file actions
64 lines (54 loc) · 1.24 KB
/
Copy pathlist_controller.rb
File metadata and controls
64 lines (54 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
63
64
require_relative 'item'
require_relative 'todo_parser'
require_relative 'todo_writer'
class ListController
attr_reader :list, :file_name
def initialize(list, file_name)
@list = list
@file_name = file_name
end
def add(content)
@list << Item.new(content)
TodoWriter.write(@file_name, @list)
#save to and update text file
end
def delete(id)
@list.delete_at(id-1)
TodoWriter.write(@file_name, @list)
end
def completed(id)
@list[id-1].completed = "X"
TodoWriter.write(@file_name, @list)
end
def display
list.each_with_index do |item, index|
if item.completed == "X"
puts "[X] #{index + 1}. #{item.content}"
else
puts "[ ] #{index + 1}. #{item.content}"
end
end
end
def display_outstanding
arr = []
list.each do |item|
if item.completed != "X"
arr << item
end
end
arr.each_with_index do |item, index|
puts "[ ] #{index + 1}. #{item.content}"
end
end
def display_completed
arr = []
list.each do |item|
if item.completed == "X"
arr << item
end
end
arr.each_with_index do |item, index|
puts "[X] #{index + 1}. #{item.content}"
end
end
end