From 031ae7f45b4be4f500a2202cdb6ba6500c164029 Mon Sep 17 00:00:00 2001 From: "alexandru.lungeanu" Date: Sun, 1 Nov 2015 20:19:23 +0200 Subject: [PATCH] Added the required classes --- code/todo_list.rb | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 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..efc0bed --- /dev/null +++ b/code/todo_list.rb @@ -0,0 +1,72 @@ +class TodoItem + 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_reader :name, :color, :items + + def initialize(name, color={}) + @name = name + @color = color[:color] + @items = [] + end + + def add(item) + if item.class == TodoItem + @items.push(item) + else + @items.push(TodoItem.new(item)) + end + end + + def items_pending + @items_pending = [] + @items.each do |x| + if !x.done? + @items_pending.push(x) + end + end + @items_pending + end + + def items_done + @items_done = [] + @items.each do |x| + if x.done? + @items_done.push(x) + end + end + @items_done + end + + def find_by_description(description) + @items.each do |x| + if x.description == description + x + end + end + end + + def set_as_done(description) + @items.each do |x| + if x.description == description + x.done! + end + end + end + +end \ No newline at end of file