mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-25 00:24:07 +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
29
app/models/recurring_todos/weekly_repeat_pattern.rb
Normal file
29
app/models/recurring_todos/weekly_repeat_pattern.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
module RecurringTodos
|
||||
|
||||
class WeeklyRepeatPattern < AbstractRepeatPattern
|
||||
|
||||
def initialize(user, attributes)
|
||||
super user, attributes
|
||||
end
|
||||
|
||||
def mapped_attributes
|
||||
mapping = @attributes
|
||||
|
||||
mapping = map(mapping, :every_other1, 'weekly_every_x_week')
|
||||
|
||||
{ monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6, sunday: 0 }.each{|day, index| mapping = map_day(mapping, :every_day, "weekly_return_#{day}", index)}
|
||||
|
||||
mapping
|
||||
end
|
||||
|
||||
def map_day(mapping, key, source_key, index)
|
||||
mapping[key] ||= ' ' # avoid nil
|
||||
mapping[source_key] ||= ' ' # avoid nil
|
||||
|
||||
mapping[key] = mapping[key][0, index] + mapping[source_key] + mapping[key][index+1, mapping[key].length]
|
||||
mapping
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue