Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homework #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions code/todo_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class TodoItem
#attr_accessor :done
attr_accessor :description
def initialize(description,done=false)
@description = description
@done = done
end
def done?
!!@done
end
def done
@done = true
end
end


class TodoList
attr_accessor :name
attr_accessor :items
def initialize(name, color = {:color => :red})
@color = color
@name = name
@items = Array.new
end
def add(item)
if item.instance_of? String
@items.push(TodoItem.new(item))
else
@items.push(item)
end
end
def items_pending
@items.find_all{|x| x.done? == false}
end
def items_done
@items.find_all{|x| x.done? == true}
end
def color
@color[:color]
end
def find_by_description(description)
@items.find{|x| x.description == description}
end
def done_by_description
@items_done.find{|x| x.description == description}
end
def set_as_done(description)
self.find_by_description(description).done
end
end