Class: RecurringTodos::DailyRepeatPattern

Inherits:
AbstractRepeatPattern show all
Defined in:
app/models/recurring_todos/daily_repeat_pattern.rb

Instance Attribute Summary

Attributes inherited from AbstractRepeatPattern

#attributes

Instance Method Summary collapse

Methods inherited from AbstractRepeatPattern

#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_occurences, #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) ⇒ DailyRepeatPattern

Returns a new instance of DailyRepeatPattern



5
6
7
# File 'app/models/recurring_todos/daily_repeat_pattern.rb', line 5

def initialize(user)
  super user
end

Instance Method Details

#every_x_daysObject



9
10
11
# File 'app/models/recurring_todos/daily_repeat_pattern.rb', line 9

def every_x_days
  get :every_other1
end

#get_next_date(previous) ⇒ Object



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

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)


13
14
15
# File 'app/models/recurring_todos/daily_repeat_pattern.rb', line 13

def only_work_days?
  get :only_work_days
end

#recurrence_patternObject



17
18
19
20
21
22
23
24
25
# File 'app/models/recurring_todos/daily_repeat_pattern.rb', line 17

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



27
28
29
30
# File 'app/models/recurring_todos/daily_repeat_pattern.rb', line 27

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