Class: RecurringTodos::RecurringTodosBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/models/recurring_todos/recurring_todos_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, attributes) ⇒ RecurringTodosBuilder

Returns a new instance of RecurringTodosBuilder


7
8
9
10
11
12
13
14
15
16
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 7

def initialize (user, attributes)
  @user = user
  @attributes = Tracks::AttributeHandler.new(@user, attributes)

  parse_dates
  parse_project
  parse_context

  @builder = create_builder(@attributes[:recurring_period])
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder


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

def builder
  @builder
end

#contextObject (readonly)

Returns the value of attribute context


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

def context
  @context
end

#projectObject (readonly)

Returns the value of attribute project


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

def project
  @project
end

#tag_listObject (readonly)

Returns the value of attribute tag_list


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

def tag_list
  @tag_list
end

#userObject (readonly)

Returns the value of attribute user


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

def user
  @user
end

Instance Method Details

#attributesObject


46
47
48
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 46

def attributes
  @builder.attributes
end

#buildObject


23
24
25
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 23

def build
  @builder.build
end

#create_builder(selector) ⇒ Object


18
19
20
21
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 18

def create_builder(selector)
  raise "Unknown recurrence selector in :recurring_period (#{selector})" unless valid_selector? selector
  eval("RecurringTodos::#{selector.capitalize}RecurringTodosBuilder.new(@user, @attributes)")
end

#errorsObject


54
55
56
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 54

def errors
  @builder.errors
end

#parse_contextObject (private)


72
73
74
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 72

def parse_context
  @context, @new_context_created = @attributes.parse_collection(:context, @user.contexts)
end

#parse_datesObject (private)


64
65
66
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 64

def parse_dates
  %w{end_date start_from}.each {|date| @attributes.parse_date date }
end

#parse_projectObject (private)


68
69
70
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 68

def parse_project
  @project, @new_project_created = @attributes.parse_collection(:project, @user.projects)
end

#patternObject


50
51
52
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 50

def pattern
  @builder.pattern
end

#recurring_todoObject


42
43
44
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 42

def recurring_todo
  @builder.recurring_todo
end

#saveObject


31
32
33
34
35
36
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 31

def save
  @builder.save_project if @new_project_created
  @builder.save_context if @new_context_created

  return @builder.save
end

#saved_recurring_todoObject


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

def saved_recurring_todo
  @builder.saved_recurring_todo
end

#update(recurring_todo) ⇒ Object


27
28
29
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 27

def update(recurring_todo)
  @builder.update(recurring_todo)
end

#valid_selector?(selector) ⇒ Boolean (private)

Returns:

  • (Boolean)

60
61
62
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 60

def valid_selector?(selector)
  %w{daily weekly monthly yearly}.include?(selector)
end