Константин обнови решението на 06.11.2013 13:52 (преди около 11 години)
+include Enumerable
+class ToDoTask
+ def initialize(status, description, priority, tags)
+ @status = status
+ @description = description
+ @priority = priority
+ @tags = tags
+
+ def each
+ yield @status
+ yield @description
+ yield @priority
+ yield @tags
+ end
+ end
+
+ def status()
+ @status.downcase.to_sym
+ end
+
+ def description()
+ @description
+ end
+
+ def priority()
+ @priority.downcase.to_sym
+ end
+
+ def tags()
+ @tags.split(', ')
+ end
+end
+
+class ToDoList
+ def self.parse(text)
+ list_of_rows = text.split("\n")
+ list_of_tasks = list_of_rows.map{|n| n.strip.split('|')}
+ @todo_list = list_of_tasks.map{|n| ToDoTask.new(n[0], n[1], n[2], n[3]) }
+ end
+
+ def self.filter(criteria)
+ @todo_list.select{ |task| task[criteria[0]] == criteria[1]}
+ end
+
+ def tasks_todo()
+ @todo_list.count{|task| task[0]=="TODO"}
+ end
+
+ def tasks_in_progress()
+ @todo_list.count{|task| task[0]=="CURRENT"}
+ end
+
+ def tasks_completed()
+ @todo_list.count{|task| task[0]=="DONE"}
+ end
+end
+
+class Criteria
+ def self.status(arg)
+ [0, arg.to_s.upcase]
+ end
+
+ def self.priority(arg)
+ [2, arg.to_s.capitalize]
+ end
+
+ def self.tags(arg)
+ [3, arg]
+ end
+end