Class: TaskWarrior::Project

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/taskwarrior/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, tasks = []) ⇒ Project

Returns a new instance of Project.



11
12
13
14
15
# File 'lib/taskwarrior/project.rb', line 11

def initialize(name, tasks = [])
  @name = name
  @tasks = tasks
  @tasks.each { |t| t.project = self }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/taskwarrior/project.rb', line 5

def name
  @name
end

#tasksObject (readonly)

Returns the value of attribute tasks.



5
6
7
# File 'lib/taskwarrior/project.rb', line 5

def tasks
  @tasks
end

Instance Method Details

#<<(task) ⇒ Object



17
18
19
20
# File 'lib/taskwarrior/project.rb', line 17

def <<(task)
  @tasks << task
  task.project = self
end

#==(other) ⇒ Object

Projects are value objects. They have no identity. If name and tasks are the same, the projects are identical.



32
33
34
35
# File 'lib/taskwarrior/project.rb', line 32

def ==(other)
  return false unless other.is_a?(Project)
  name.eql?(other.name) && tasks.eql?(other.tasks)
end

#hashObject



26
27
28
# File 'lib/taskwarrior/project.rb', line 26

def hash
  name.hash + tasks.hash
end

#to_sObject



22
23
24
# File 'lib/taskwarrior/project.rb', line 22

def to_s
  "Project #{name} (#{@tasks.size} tasks)"
end