Class: RecurringTodos::WeeklyRecurrencePattern
Instance Attribute Summary
#attributes
Instance Method Summary
collapse
#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
Returns a new instance of WeeklyRecurrencePattern.
3
4
5
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 3
def initialize(user)
super user
end
|
Instance Method Details
#determine_start_date(previous) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 54
def determine_start_date(previous)
if previous.nil?
return start_from || Time.zone.now
else
start = previous + 1.day
if start.wday == 0
start += (every_x_week - 1).week
end
unless start_from.nil?
start = start_from if start_from > previous
end
return start
end
end
|
#every_x_week ⇒ Object
7
8
9
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 7
def every_x_week
get :every_other1
end
|
#find_first_day_in_this_week(start) ⇒ Object
73
74
75
76
77
78
79
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 73
def find_first_day_in_this_week(start)
start.wday.upto 6 do |i|
return start + (i - start.wday).days if on_xday(i)
end
-1
end
|
#get_next_date(previous) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 36
def get_next_date(previous)
start = determine_start_date(previous)
day = find_first_day_in_this_week(start)
return day unless day == -1
start = start + every_x_week.week - (start.wday).days
start = find_first_day_in_this_week(start)
return start unless start == -1
raise Exception.new, "unable to find next weekly date (#{every_day})"
end
|
#on_xday(n) ⇒ Object
17
18
19
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 17
def on_xday(n)
get(:every_day) && get(:every_day)[n, 1] != ' '
end
|
#recurrence_pattern ⇒ Object
21
22
23
24
25
26
27
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 21
def recurrence_pattern
if every_x_week > 1
I18n.t("todos.recurrence.pattern.every_n", :n => every_x_week) + " " + I18n.t("common.weeks")
else
I18n.t('todos.recurrence.pattern.weekly')
end
end
|
#validate ⇒ Object
29
30
31
32
33
34
|
# File 'app/models/recurring_todos/weekly_recurrence_pattern.rb', line 29
def validate
super
validate_not_blank(every_x_week, "Every other nth week may not be empty for weekly recurrence setting")
something_set = %w{ sunday monday tuesday wednesday thursday friday saturday }.inject(false) { |set, day| set || send("on_#{day}") }
errors.add(:base, "You must specify at least one day on which the todo recurs") unless something_set
end
|