Class: ProjectFromTodo

Inherits:
Object
  • Object
show all
Defined in:
lib/project_from_todo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(todo) ⇒ ProjectFromTodo

Returns a new instance of ProjectFromTodo.



4
5
6
# File 'lib/project_from_todo.rb', line 4

def initialize(todo)
  @todo = todo
end

Instance Attribute Details

#todoObject (readonly)

Returns the value of attribute todo.



2
3
4
# File 'lib/project_from_todo.rb', line 2

def todo
  @todo
end

Instance Method Details

#build_projectObject



19
20
21
22
23
24
25
26
27
# File 'lib/project_from_todo.rb', line 19

def build_project
  project = Project.new.tap do |p|
    p.name = todo.description
    p.description = todo.notes
    p.default_context = todo.context
    p.default_tags = todo.tag_list
    p.user = todo.user
  end
end

#createObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/project_from_todo.rb', line 8

def create
  project = build_project

  if project.valid?
    todo.destroy
    project.save!
  end

  project
end