move mapping of form attributes to model attributes from pattern to builder to make

pattern independent of form
This commit is contained in:
Reinier Balt 2014-02-07 22:55:52 +01:00
parent 1f36c27af8
commit 776a046465
22 changed files with 463 additions and 446 deletions

View file

@ -2,24 +2,8 @@ module RecurringTodos
class MonthlyRepeatPattern < AbstractRepeatPattern
def initialize(user, attributes)
super user, attributes
@selector = get_selector('monthly_selector')
end
def mapped_attributes
mapping = @attributes
mapping = map(mapping, :every_other1, 'monthly_every_x_day')
mapping = map(mapping, :every_other3, 'monthly_every_xth_day')
mapping = map(mapping, :every_count, 'monthly_day_of_week')
mapping[:every_other2] = mapping[get_every_other2]
mapping = mapping.except('monthly_every_x_month').except('monthly_every_x_month2')
mapping[:recurrence_selector] = get_recurrence_selector
mapping
def initialize(user)
super user
end
def every_x_day?
@ -30,20 +14,6 @@ module RecurringTodos
@recurring_todo.recurrence_selector == 1
end
private
def get_recurrence_selector
@selector=='monthly_every_x_day' ? 0 : 1
end
def get_every_other2
get_recurrence_selector == 0 ? 'monthly_every_x_month' : 'monthly_every_x_month2'
end
def valid_selector?(selector)
%w{monthly_every_x_day monthly_every_xth_day}.include?(selector)
end
end
end