From 2eae82ecdb3b52c6cb404116c65b94981df8457a Mon Sep 17 00:00:00 2001 From: mindit_marian_sichitiu Date: Fri, 6 Nov 2015 19:43:39 +0200 Subject: [PATCH 1/2] homework --- code/todo_list.rb | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 code/todo_list.rb diff --git a/code/todo_list.rb b/code/todo_list.rb new file mode 100644 index 0000000..cd4df8d --- /dev/null +++ b/code/todo_list.rb @@ -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 \ No newline at end of file From 72257adb4ac8906adaa01423c5607f4f473108f6 Mon Sep 17 00:00:00 2001 From: Sichitiu Marian Date: Fri, 6 Nov 2015 19:51:13 +0200 Subject: [PATCH 2/2] Update todo_list.rb --- code/todo_list.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/todo_list.rb b/code/todo_list.rb index cd4df8d..a1071e3 100644 --- a/code/todo_list.rb +++ b/code/todo_list.rb @@ -8,7 +8,7 @@ def initialize(description,done=false) def done? !!@done end - def done! + def done @done = true end end @@ -45,6 +45,6 @@ def done_by_description @items_done.find{|x| x.description == description} end def set_as_done(description) - self.find_by_description(description).done! + self.find_by_description(description).done end -end \ No newline at end of file +end