Class: RecurringTodos::YearlyRecurrencePattern
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 YearlyRecurrencePattern.
3
4
5
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 3
def initialize(user)
super user
end
|
Instance Method Details
#date_as_month_day ⇒ Object
76
77
78
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 76
def date_as_month_day
I18n.l(DateTime.new(Time.zone.now.year, month_of_year, every_x_day), :format => :month_day)
end
|
#day_of_week ⇒ Object
23
24
25
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 23
def day_of_week
get :every_count
end
|
#every_x_day ⇒ Object
15
16
17
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 15
def every_x_day
get :every_other1
end
|
#every_xth_day ⇒ Object
19
20
21
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 19
def every_xth_day
get :every_other3
end
|
#get_next_date(previous) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 61
def get_next_date(previous)
start = determine_start(previous)
month = get(:every_other2)
case recurrence_selector
when 0 return get_specific_day_of_month(start, month)
when 1 return get_relative_weekday_of_month(start, month)
end
nil
end
|
#get_relative_weekday_of_month(start, month) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 92
def get_relative_weekday_of_month(start, month)
the_next = start.month > month ? Time.zone.local(start.year + 1, month, 1) : start
the_next = get_xth_day_of_month(every_xth_day, day_of_week, month, the_next.year)
the_next = get_xth_day_of_month(every_xth_day, day_of_week, month, start.year + 1) if the_next <= start
the_next
end
|
#get_specific_day_of_month(start, month) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 80
def get_specific_day_of_month(start, month)
if start.month > month || (start.month == month && start.day >= every_x_day)
start = Time.zone.local(start.year + 1, month, 1)
else
start = Time.zone.local(start.year, month, 1)
end
Time.zone.local(start.year, month, every_x_day)
end
|
#month_of_year ⇒ Object
11
12
13
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 11
def month_of_year
get :every_other2
end
|
#month_of_year2 ⇒ Object
27
28
29
30
31
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 27
def month_of_year2
get(:recurrence_selector) == 1 ? get(:every_other2) : Time.zone.now.month
end
|
#recurrence_pattern ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 33
def recurrence_pattern
if recurrence_selector == 0
I18n.t("todos.recurrence.pattern.every_year_on", :date => date_as_month_day)
else
I18n.t("todos.recurrence.pattern.every_year_on",
:date => I18n.t("todos.recurrence.pattern.the_xth_day_of_month",
:x => xth(every_xth_day),
:day => day_of_week_as_text(day_of_week),
:month => month_of_year_as_text(month_of_year)
))
end
end
|
#recurrence_selector ⇒ Object
7
8
9
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 7
def recurrence_selector
get :recurrence_selector
end
|
#validate ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/models/recurring_todos/yearly_recurrence_pattern.rb', line 46
def validate
super
case recurrence_selector
when 0 validate_not_blank(month_of_year, "The month of the year may not be empty for recurrence setting")
validate_not_blank(every_x_day, "The day of the month may not be empty for recurrence setting")
when 1 validate_not_blank(month_of_year2, "The month of the year may not be empty for recurrence setting")
validate_not_blank(every_xth_day, "The nth day of the month may not be empty for recurrence setting")
validate_not_blank(day_of_week, "The day of the week may not be empty for recurrence setting")
else
raise "unexpected value of recurrence selector '#{recurrence_selector}'"
end
end
|