mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-12 07:32:37 +01:00
Start major refactoring of recurring_todos. Started with creating new recurring todos.
All current and new tests pass
This commit is contained in:
parent
8e13059df1
commit
78c07d52b7
26 changed files with 1218 additions and 32 deletions
46
app/models/recurring_todos/yearly_repeat_pattern.rb
Normal file
46
app/models/recurring_todos/yearly_repeat_pattern.rb
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
module RecurringTodos
|
||||
|
||||
class YearlyRepeatPattern < AbstractRepeatPattern
|
||||
|
||||
def initialize(user, attributes)
|
||||
super user, attributes
|
||||
@selector = get_selector('yearly_selector')
|
||||
end
|
||||
|
||||
def mapped_attributes
|
||||
mapping = @attributes
|
||||
|
||||
mapping[:recurrence_selector] = get_recurrence_selector
|
||||
|
||||
mapping[:every_other2] = mapping[get_every_other2]
|
||||
mapping = mapping.except('yearly_month_of_year').except('yearly_month_of_year2')
|
||||
|
||||
mapping = map(mapping, :every_other1, 'yearly_every_x_day')
|
||||
mapping = map(mapping, :every_other3, 'yearly_every_xth_day')
|
||||
mapping = map(mapping, :every_count, 'yearly_day_of_week')
|
||||
|
||||
mapping
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_recurrence_selector
|
||||
@selector=='yearly_every_x_day' ? 0 : 1
|
||||
end
|
||||
|
||||
def get_every_other2
|
||||
case get_recurrence_selector
|
||||
when 0
|
||||
'yearly_month_of_year'
|
||||
when 1
|
||||
'yearly_month_of_year2'
|
||||
end
|
||||
end
|
||||
|
||||
def valid_selector?(selector)
|
||||
%w{yearly_every_x_day yearly_every_xth_day}.include?(selector)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue