Class: RubyTodo::Notebook
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RubyTodo::Notebook
- Defined in:
- lib/ruby_todo/models/notebook.rb
Class Method Summary collapse
Instance Method Summary collapse
- #archived_tasks ⇒ Object
- #done_tasks ⇒ Object
- #due_soon_tasks ⇒ Object
- #high_priority_tasks ⇒ Object
- #in_progress_tasks ⇒ Object
- #is_default? ⇒ Boolean
- #low_priority_tasks ⇒ Object
- #make_default! ⇒ Object
- #medium_priority_tasks ⇒ Object
- #overdue_tasks ⇒ Object
- #statistics ⇒ Object
- #tasks_by_priority(priority) ⇒ Object
- #tasks_by_status(status) ⇒ Object
- #tasks_with_tag(tag) ⇒ Object
- #todo_tasks ⇒ Object
Class Method Details
.default_notebook ⇒ Object
18 19 20 |
# File 'lib/ruby_todo/models/notebook.rb', line 18 def self.default_notebook find_by(is_default: true) end |
Instance Method Details
#archived_tasks ⇒ Object
65 66 67 |
# File 'lib/ruby_todo/models/notebook.rb', line 65 def archived_tasks tasks_by_status("archived") end |
#done_tasks ⇒ Object
61 62 63 |
# File 'lib/ruby_todo/models/notebook.rb', line 61 def done_tasks tasks_by_status("done") end |
#due_soon_tasks ⇒ Object
49 50 51 |
# File 'lib/ruby_todo/models/notebook.rb', line 49 def due_soon_tasks tasks.select(&:due_soon?) end |
#high_priority_tasks ⇒ Object
69 70 71 |
# File 'lib/ruby_todo/models/notebook.rb', line 69 def high_priority_tasks tasks_by_priority("high") end |
#in_progress_tasks ⇒ Object
57 58 59 |
# File 'lib/ruby_todo/models/notebook.rb', line 57 def in_progress_tasks tasks_by_status("in_progress") end |
#is_default? ⇒ Boolean
29 30 31 |
# File 'lib/ruby_todo/models/notebook.rb', line 29 def is_default? is_default end |
#low_priority_tasks ⇒ Object
77 78 79 |
# File 'lib/ruby_todo/models/notebook.rb', line 77 def low_priority_tasks tasks_by_priority("low") end |
#make_default! ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ruby_todo/models/notebook.rb', line 22 def make_default! transaction do Notebook.where.not(id: id).update_all(is_default: false) update!(is_default: true) end end |
#medium_priority_tasks ⇒ Object
73 74 75 |
# File 'lib/ruby_todo/models/notebook.rb', line 73 def medium_priority_tasks tasks_by_priority("medium") end |
#overdue_tasks ⇒ Object
45 46 47 |
# File 'lib/ruby_todo/models/notebook.rb', line 45 def overdue_tasks tasks.select(&:overdue?) end |
#statistics ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ruby_todo/models/notebook.rb', line 81 def statistics { total: tasks.count, todo: tasks.where(status: "todo").count, in_progress: tasks.where(status: "in_progress").count, done: tasks.where(status: "done").count, archived: tasks.where(status: "archived").count, overdue: tasks.select(&:overdue?).count, due_soon: tasks.select(&:due_soon?).count, high_priority: tasks.where(priority: "high").count, medium_priority: tasks.where(priority: "medium").count, low_priority: tasks.where(priority: "low").count } end |
#tasks_by_priority(priority) ⇒ Object
37 38 39 |
# File 'lib/ruby_todo/models/notebook.rb', line 37 def tasks_by_priority(priority) tasks.where(priority: priority) end |
#tasks_by_status(status) ⇒ Object
33 34 35 |
# File 'lib/ruby_todo/models/notebook.rb', line 33 def tasks_by_status(status) tasks.where(status: status) end |
#tasks_with_tag(tag) ⇒ Object
41 42 43 |
# File 'lib/ruby_todo/models/notebook.rb', line 41 def tasks_with_tag(tag) tasks.select { |task| task.has_tag?(tag) } end |
#todo_tasks ⇒ Object
53 54 55 |
# File 'lib/ruby_todo/models/notebook.rb', line 53 def todo_tasks tasks_by_status("todo") end |