From 4ac3632fb9318dbfb0a4c25ef36551fe6ddc4878 Mon Sep 17 00:00:00 2001 From: Henrik Bohre Date: Thu, 20 Aug 2009 09:54:22 +0200 Subject: [PATCH] #300: Renamed to todo_from_specification --- app/models/todo.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/models/todo.rb b/app/models/todo.rb index ba44dd94..b73d19c0 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -83,7 +83,13 @@ class Todo < ActiveRecord::Base end - def todo_from_string(specification) + # Returns a string with description + def specification + project_name = project.is_a?(NullProject) ? "(none)" : project.name + return "#{description} <#{context.title}; #{project_name}>" + end + + def todo_from_specification(specification) # Split specification into parts: description parts = specification.split(%r{\ \<|; |\>}) return nil unless parts.length == 3 @@ -107,7 +113,7 @@ class Todo < ActiveRecord::Base end unless @predecessor_array.nil? # Only validate predecessors if they changed @predecessor_array.each do |specification| - t = todo_from_string(specification) + t = todo_from_specification(specification) if t.nil? errors.add("Depends on:", "Could not find action '#{h(specification)}'") else @@ -117,12 +123,6 @@ class Todo < ActiveRecord::Base end end - # Returns a string with description, project and context - def specification - project_name = project.is_a?(NullProject) ? "(none)" : project.name - return "#{description} <#{context.title}; #{project_name}>" - end - def save_predecessors unless @predecessor_array.nil? # Only save predecessors if they changed current_array = predecessors.map{|p| p.specification} @@ -131,12 +131,12 @@ class Todo < ActiveRecord::Base # This is probably a bit naive code... remove_array.each do |specification| - t = todo_from_string(specification) + t = todo_from_specification(specification) self.predecessors.delete(t) unless t.nil? end # ... as is this? add_array.each do |specification| - t = todo_from_string(specification) + t = todo_from_specification(specification) unless t.nil? self.predecessors << t unless self.predecessors.include?(t) else @@ -253,8 +253,7 @@ class Todo < ActiveRecord::Base def from_recurring_todo? return self.recurring_todo_id != nil end - - # TODO: DELIMITER + # TODO: Should possibly handle state changes also? def add_predecessor_list(predecessor_list) if predecessor_list.kind_of? String