Class: RecurringTodo
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RecurringTodo
- Includes:
- AASM, IsTaggable
- Defined in:
- app/models/recurring_todo.rb
Instance Method Summary collapse
- #clear_todos_association ⇒ Object
- #continues_recurring?(previous) ⇒ Boolean
- #done?(end_date) ⇒ Boolean
- #get_due_date(previous) ⇒ Object
- #get_show_from_date(previous) ⇒ Object
- #increment_occurrences ⇒ Object
-
#pattern ⇒ Object
the following recurrence patterns can be stored:.
- #pattern_specific_validations ⇒ Object
- #period_validation ⇒ Object
- #recurrence_pattern ⇒ Object
- #recurring_target_as_text ⇒ Object
- #remove_from_project! ⇒ Object
- #starred? ⇒ Boolean
- #toggle_completion! ⇒ Object
- #toggle_star! ⇒ Object
- #valid_period? ⇒ Boolean
Methods included from IsTaggable
Instance Method Details
#clear_todos_association ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'app/models/recurring_todo.rb', line 126 def clear_todos_association unless todos.nil? todos.each do |t| t.recurring_todo = nil t.save end end end |
#continues_recurring?(previous) ⇒ Boolean
140 141 142 |
# File 'app/models/recurring_todo.rb', line 140 def continues_recurring?(previous) pattern.continues_recurring?(previous) end |
#done?(end_date) ⇒ Boolean
103 104 105 |
# File 'app/models/recurring_todo.rb', line 103 def done?(end_date) !continues_recurring?(end_date) end |
#get_due_date(previous) ⇒ Object
95 96 97 |
# File 'app/models/recurring_todo.rb', line 95 def get_due_date(previous) pattern.get_due_date(previous) end |
#get_show_from_date(previous) ⇒ Object
99 100 101 |
# File 'app/models/recurring_todo.rb', line 99 def get_show_from_date(previous) pattern.get_show_from_date(previous) end |
#increment_occurrences ⇒ Object
135 136 137 138 |
# File 'app/models/recurring_todo.rb', line 135 def increment_occurrences self.occurrences_count += 1 save end |
#pattern ⇒ Object
the following recurrence patterns can be stored:
daily todos – recurrence_period = ‘daily’ every nth day – nth stored in every_other1 every work day – only_work_days = true tracks will choose between both options using only_work_days weekly todos – recurrence_period = ‘weekly’ every nth week on a specific day - nth stored in every_other1 and the specific day is stored in every_day monthly todos – recurrence_period = ‘monthly’ every day x of nth month – x stored in every_other1 and nth is stored in every_other2 the xth y-day of every nth month (the forth tuesday of every 2 months) - x stored in every_other3, y stored in every_count, nth stored in every_other2 choosing between both options is done on recurrence_selector where 0 is for first type and 1 for second type yearly todos – recurrence_period = ‘yearly’ every day x of month y – x is stored in every_other1, y is stored in every_other2 the x-th day y of month z (the forth tuesday of september) - x is stored in every_other3, y is stored in every_count, z is stored in every_other2 choosing between both options is done on recurrence_selector where 0 is for first type and 1 for second type
75 76 77 78 79 80 81 |
# File 'app/models/recurring_todo.rb', line 75 def pattern if valid_period? @pattern = eval("RecurringTodos::#{recurring_period.capitalize}RecurrencePattern.new(user)", binding, __FILE__, __LINE__) @pattern.build_from_recurring_todo(self) end @pattern end |
#pattern_specific_validations ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/models/recurring_todo.rb', line 37 def pattern_specific_validations if pattern pattern.validate else errors[:recurring_todo] << "Invalid recurrence period '#{recurring_period}'" end end |
#period_validation ⇒ Object
49 50 51 |
# File 'app/models/recurring_todo.rb', line 49 def period_validation errors.add(:recurring_period, "is an unknown recurrence pattern: '#{recurring_period}'") unless valid_period? end |
#recurrence_pattern ⇒ Object
83 84 85 |
# File 'app/models/recurring_todo.rb', line 83 def recurrence_pattern pattern.recurrence_pattern end |
#recurring_target_as_text ⇒ Object
87 88 89 |
# File 'app/models/recurring_todo.rb', line 87 def recurring_target_as_text pattern.recurring_target_as_text end |
#remove_from_project! ⇒ Object
121 122 123 124 |
# File 'app/models/recurring_todo.rb', line 121 def remove_from_project! self.project = nil save end |
#starred? ⇒ Boolean
91 92 93 |
# File 'app/models/recurring_todo.rb', line 91 def starred? has_tag?(Todo::STARRED_TAG_NAME) end |
#toggle_completion! ⇒ Object
107 108 109 |
# File 'app/models/recurring_todo.rb', line 107 def toggle_completion! completed? ? activate! : complete! end |
#toggle_star! ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'app/models/recurring_todo.rb', line 111 def toggle_star! if starred? (Todo::STARRED_TAG_NAME) else (Todo::STARRED_TAG_NAME) end .reload starred? end |
#valid_period? ⇒ Boolean
45 46 47 |
# File 'app/models/recurring_todo.rb', line 45 def valid_period? %W[daily weekly monthly yearly].include?(recurring_period) end |