Class: Todd::TodoList
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Todd::TodoList
- Defined in:
- lib/todd/model.rb
Instance Method Summary collapse
- #add(task_str) ⇒ Object
- #archive(query) ⇒ Object
- #bundle(query = nil, archived = false) ⇒ Object
- #category_ids ⇒ Object
- #restore(query) ⇒ Object
- #rm(query) ⇒ Object
- #start(query) ⇒ Object
- #stop(query) ⇒ Object
Instance Method Details
#add(task_str) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/todd/model.rb', line 84 def add task_str category_name = Base[:default_category] task_str = task_str.sub(/#(\S*)/) do |cat| puts "Category: #{$1}" category_name = $1 "" # this kills the category in the task_str end task_str.strip! puts "Task #{task_str}" category = self.categories.find_or_create_by_name(category_name) task = category.tasks.create(:title => task_str) end |
#archive(query) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/todd/model.rb', line 106 def archive query DB.find(query, category_ids) do |t| t = t.archive! puts t ? "Archived Task #{t.id}" : "Cannot archive active task" end end |
#bundle(query = nil, archived = false) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/todd/model.rb', line 69 def bundle query = nil, archived = false bund = { :type => :todolist, :categories => [] } self.categories.each do |cat| next unless cat.visible? sub_bundle = cat.bundle(query, archived) bund[:categories] << sub_bundle unless sub_bundle[:tasks] == [] end bund end |
#category_ids ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/todd/model.rb', line 58 def category_ids return @_category_ids if @_category_ids @_category_ids = [] self.categories.find_each do |cat| @_category_ids << cat.id end @_category_ids end |
#restore(query) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/todd/model.rb', line 113 def restore query DB.find(query, category_ids, true) do |t| puts "Restored Task #{t.id}" t.restore! end end |
#rm(query) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/todd/model.rb', line 99 def rm query DB.find(query, category_ids) do |t| puts "Removed Task #{t.id}" t.destroy end end |
#start(query) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/todd/model.rb', line 120 def start query DB.find(query, category_ids) do |t| t = t.start! puts t ? "Task #{t.id} started" : "Task already running" end end |
#stop(query) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/todd/model.rb', line 127 def stop query DB.find(query, category_ids) do |t| t = t.stop! puts t ? "Task #{t.id} stopped" : "Task already stopped" puts Util.format_bundle t.bundle if t end end |