Class: RecurringTodos::WeeklyRecurringTodosBuilder

Inherits:
AbstractRecurringTodosBuilder show all
Defined in:
app/models/recurring_todos/weekly_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) ⇒ WeeklyRecurringTodosBuilder

Returns a new instance of WeeklyRecurringTodosBuilder


6
7
8
# File 'app/models/recurring_todos/weekly_recurring_todos_builder.rb', line 6

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

Instance Attribute Details

#recurring_todoObject (readonly)

Returns the value of attribute recurring_todo


4
5
6
# File 'app/models/recurring_todos/weekly_recurring_todos_builder.rb', line 4

def recurring_todo
  @recurring_todo
end

Instance Method Details

#attributes_to_filterObject


10
11
12
# File 'app/models/recurring_todos/weekly_recurring_todos_builder.rb', line 10

def attributes_to_filter
  %w{weekly_selector weekly_every_x_week} + %w{monday tuesday wednesday thursday friday saturday sunday}.map{|day| "weekly_return_#{day}" }
end

#map_attributes(mapping) ⇒ Object


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

def map_attributes(mapping)
  mapping = map(mapping, :every_other1, 'weekly_every_x_week')

  { monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6, sunday: 0 }
  .each do |day, index|
    mapping = map_day(mapping, :every_day, "weekly_return_#{day}", index)
  end

  mapping
end

#map_day(mapping, key, source_key, index) ⇒ Object


25
26
27
28
29
30
31
# File 'app/models/recurring_todos/weekly_recurring_todos_builder.rb', line 25

def map_day(mapping, key, source_key, index)
  mapping.set_if_nil(key, '       ')  # avoid nil
  mapping.set_if_nil(source_key, ' ') # avoid nil

  mapping.set(key, mapping.get(key)[0, index] + mapping.get(source_key) + mapping.get(key)[index+1, mapping.get(key).length])
  mapping.except(source_key)
end

#selector_keyObject


33
34
35
# File 'app/models/recurring_todos/weekly_recurring_todos_builder.rb', line 33

def selector_key
  nil
end

#valid_selector?(key) ⇒ Boolean

Returns:

  • (Boolean)

37
38
39
# File 'app/models/recurring_todos/weekly_recurring_todos_builder.rb', line 37

def valid_selector?(key)
  true
end