Class: RecurringTodo

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AASM, IsTaggable
Defined in:
app/models/recurring_todo.rb

Instance Method Summary collapse

Methods included from IsTaggable

included

Instance Method Details

#clear_todos_associationObject


124
125
126
127
128
129
130
131
# File 'app/models/recurring_todo.rb', line 124

def clear_todos_association
  unless todos.nil?
    self.todos.each do |t|
      t.recurring_todo = nil
      t.save
    end
  end
end

#continues_recurring?(previous) ⇒ Boolean

Returns:

  • (Boolean)

138
139
140
# File 'app/models/recurring_todo.rb', line 138

def continues_recurring?(previous)
  pattern.continues_recurring?(previous)
end

#done?(end_date) ⇒ Boolean

Returns:

  • (Boolean)

101
102
103
# File 'app/models/recurring_todo.rb', line 101

def done?(end_date)
  !continues_recurring?(end_date)
end

#get_due_date(previous) ⇒ Object


93
94
95
# File 'app/models/recurring_todo.rb', line 93

def get_due_date(previous)
  pattern.get_due_date(previous)
end

#get_show_from_date(previous) ⇒ Object


97
98
99
# File 'app/models/recurring_todo.rb', line 97

def get_show_from_date(previous)
  pattern.get_show_from_date(previous)
end

#increment_occurrencesObject


133
134
135
136
# File 'app/models/recurring_todo.rb', line 133

def increment_occurrences
  self.occurences_count += 1
  self.save
end

#patternObject

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


73
74
75
76
77
78
79
# File 'app/models/recurring_todo.rb', line 73

def pattern
  if valid_period?
    @pattern = eval("RecurringTodos::#{recurring_period.capitalize}RepeatPattern.new(user)")
    @pattern.build_from_recurring_todo(self)
  end
  @pattern
end

#pattern_specific_validationsObject


35
36
37
38
39
40
41
# File 'app/models/recurring_todo.rb', line 35

def pattern_specific_validations
  if pattern
    pattern.validate
  else
    errors[:recurring_todo] << "Invalid recurrence period '#{recurring_period}'"
  end
end

#period_validationObject


47
48
49
# File 'app/models/recurring_todo.rb', line 47

def period_validation
  errors.add(:recurring_period, "is an unknown recurrence pattern: '#{recurring_period}'") unless valid_period?
end

#recurrence_patternObject


81
82
83
# File 'app/models/recurring_todo.rb', line 81

def recurrence_pattern
  pattern.recurrence_pattern
end

#recurring_target_as_textObject


85
86
87
# File 'app/models/recurring_todo.rb', line 85

def recurring_target_as_text
  pattern.recurring_target_as_text
end

#remove_from_project!Object


119
120
121
122
# File 'app/models/recurring_todo.rb', line 119

def remove_from_project!
  self.project = nil
  self.save
end

#starred?Boolean

Returns:

  • (Boolean)

89
90
91
# File 'app/models/recurring_todo.rb', line 89

def starred?
  has_tag?(Todo::STARRED_TAG_NAME)
end

#toggle_completion!Object


105
106
107
# File 'app/models/recurring_todo.rb', line 105

def toggle_completion!
  completed? ? activate! : complete!
end

#toggle_star!Object


109
110
111
112
113
114
115
116
117
# File 'app/models/recurring_todo.rb', line 109

def toggle_star!
  if starred?
    _remove_tags(Todo::STARRED_TAG_NAME)
  else
    _add_tags(Todo::STARRED_TAG_NAME)
  end
  tags.reload
  starred?
end

#valid_period?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'app/models/recurring_todo.rb', line 43

def valid_period?
  %W[daily weekly monthly yearly].include?(recurring_period)
end