Class: RecurringTodos::YearlyRecurringTodosBuilder

Inherits:
AbstractRecurringTodosBuilder show all
Defined in:
app/models/recurring_todos/yearly_recurring_todos_builder.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractRecurringTodosBuilder

#mapped_attributes, #pattern

Instance Method Summary collapse

Methods inherited from AbstractRecurringTodosBuilder

#attributes, #build, #errors, #filter_attributes, #filter_generic_attributes, #get_selector, #map, #save, #save_collection, #save_context, #save_project, #save_recurring_todo, #save_tags, #saved_recurring_todo, #tag_list_or_empty_string, #update

Constructor Details

#initialize(user, attributes) ⇒ YearlyRecurringTodosBuilder

Returns a new instance of YearlyRecurringTodosBuilder.



5
6
7
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 5

def initialize(user, attributes)
  super(user, attributes, YearlyRecurrencePattern)
end

Instance Attribute Details

#recurring_todoObject (readonly)

Returns the value of attribute recurring_todo.



3
4
5
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 3

def recurring_todo
  @recurring_todo
end

Instance Method Details

#attributes_to_filterObject



9
10
11
12
13
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 9

def attributes_to_filter
  %w{ yearly_selector     yearly_month_of_year  yearly_month_of_year2
      yearly_every_x_day  yearly_every_xth_day  yearly_day_of_week
  }
end

#get_every_other2Object



38
39
40
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 38

def get_every_other2
  { 0 => :yearly_month_of_year, 1 => :yearly_month_of_year2 }[get_recurrence_selector]
end

#get_recurrence_selectorObject



34
35
36
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 34

def get_recurrence_selector
  @selector == 'yearly_every_x_day' ? 0 : 1
end

#map_attributes(mapping) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 15

def map_attributes(mapping)
  mapping.set(:recurrence_selector, get_recurrence_selector)
  mapping.set(:every_other2,        mapping.get(get_every_other2))

  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.except(:yearly_month_of_year).except(:yearly_month_of_year2)
end

#selector_keyObject



26
27
28
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 26

def selector_key
  :yearly_selector
end

#valid_selector?(selector) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/recurring_todos/yearly_recurring_todos_builder.rb', line 30

def valid_selector?(selector)
  %w{yearly_every_x_day yearly_every_xth_day}.include?(selector.to_s)
end