-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_manager.rb
58 lines (58 loc) · 1.84 KB
/
list_manager.rb
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
module ListManager
# add a to-do to an existing to-do list
def add_to_do(task, notes=nil, location=nil, complete=false)
list << ToDo.new(task, notes, location, complete)
puts "'#{task}' added to '#{self.name}.'"
end
# remove a to-do from an existing to-do list
def remove_to_do(identifier)
removed = list.collect do |to_do|
to_do if to_do.values.include?(identifier)
end.compact
removed.each { |to_do| puts "'#{to_do.task}' removed from '#{self.name}.'" }
list.delete_if { |to_do| to_do.values.include?(identifier) }
end
# remove all to-dos from an existing to-do list
def remove_all
list.clear
puts "All to-do's have been removed from '#{self.name}.'"
end
# mark a to-do complete (status=true) or incomplete (status=false)
# based on an identifier (i.e. task, notes, location, complete, etc.)
def mark_complete(identifier, status=true)
complete = list.collect do |to_do|
to_do if to_do.values.include?(identifier)
end.compact
complete.each do |to_do|
if to_do.complete == false
puts "'#{to_do.task}' marked as complete in '#{self.name}.'"
else
puts "'#{to_do.task}' marked as incomplete in '#{self.name}.'"
end
end
list.each do |to_do|
to_do.complete = status if to_do.values.include?(identifier)
end
end
# print complete, incomplete, or all to-dos
def print_list(complete=false, all=false)
case all
when false
list.each do |to_do|
if to_do.complete == complete
puts "Task: #{to_do.task}"
puts "Notes: #{to_do.notes}"
puts "Location: #{to_do.location}"
puts ""
end
end
when true
list.each do |to_do|
puts "Task: #{to_do.task}"
puts "Notes: #{to_do.notes}"
puts "Location: #{to_do.location}"
puts ""
end
end
end
end