Class: RecurringTodos::DailyRecurrencePattern

Inherits:
AbstractRecurrencePattern show all
Defined in:
app/models/recurring_todos/daily_recurrence_pattern.rb

Instance Attribute Summary

Attributes inherited from AbstractRecurrencePattern

#attributes

Instance Method Summary collapse

Methods inherited from AbstractRecurrencePattern

#build_from_recurring_todo, #build_recurring_todo, #continues_recurring?, #day_of_week_as_text, #determine_start, #end_date, #ends_on, #errors, #find_last_day_x_of_month, #find_xth_day_of_month, #get, #get_due_date, #get_show_from_date, #get_xth_day_of_month, #month_of_year_as_text, #number_of_occurrences, #put_in_tickler?, #recurring_target_as_text, #set_recurrence_on_validations, #show_always?, #show_from_delta, #start_from, #starts_and_ends_on_validations, #target, #update_recurring_todo, #valid?, #validate_not_blank, #validate_not_nil, #xth

Constructor Details

#initialize(user) ⇒ DailyRecurrencePattern

Returns a new instance of DailyRecurrencePattern.



3
4
5
# File 'app/models/recurring_todos/daily_recurrence_pattern.rb', line 3

def initialize(user)
  super user
end

Instance Method Details

#every_x_daysObject



7
8
9
# File 'app/models/recurring_todos/daily_recurrence_pattern.rb', line 7

def every_x_days
  get :every_other1
end

#get_next_date(previous) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/recurring_todos/daily_recurrence_pattern.rb', line 30

def get_next_date(previous)
  # previous is the due date of the previous todo or it is the completed_at
  # date when the completed_at date is after due_date (i.e. you did not make
  # the due date in time)

  start = determine_start(previous, 1.day)

  if only_work_days?
    # jump over weekend if necessary
    return start + 2.day if start.wday == 6 # saturday
    return start + 1.day if start.wday == 0 # sunday
    return start
  else
    # if there was no previous todo, do not add n: the first todo starts on
    # today or on start_from
    return previous == nil ? start : start + every_x_days.day - 1.day
  end
end

#only_work_days?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/models/recurring_todos/daily_recurrence_pattern.rb', line 11

def only_work_days?
  get :only_work_days
end

#recurrence_patternObject



15
16
17
18
19
20
21
22
23
# File 'app/models/recurring_todos/daily_recurrence_pattern.rb', line 15

def recurrence_pattern
  if only_work_days?
    I18n.t("todos.recurrence.pattern.on_work_days")
  elsif every_x_days > 1
    I18n.t("todos.recurrence.pattern.every_n_days", :n => every_x_days)
  else
    I18n.t("todos.recurrence.pattern.every_day")
  end
end

#validateObject



25
26
27
28
# File 'app/models/recurring_todos/daily_recurrence_pattern.rb', line 25

def validate
  super
  errors.add(:base, "Every other nth day may not be empty for this daily recurrence setting") if (!only_work_days?) && every_x_days.blank?
end