Class: Taskish::Project

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

Overview

Taskish::Project - A single project

USAGE

Taskish::Project.new(project) do |project|
  # Get project's name
  project.name

  # Add task to project
  project << Taskish::Task.new( project.name, 'my task' )

  # Add child project to project
  project << Taskish::Project.new( 'child project' )

  # Get project's child projects
  project.projects

  # Get project's tasks
  project.tasks

end

SEE ALSO

<Taskish>, <Taskish::Task>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) {|_self| ... } ⇒ Project

Returns a new instance of Project.

Yields:

  • (_self)

Yield Parameters:



34
35
36
37
38
39
# File 'lib/taskish/project.rb', line 34

def initialize(project)
  @name     = project
  @children = []
  @parent   = nil
  yield self if block_given?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

Instance Method Details

#<<(child) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/taskish/project.rb', line 41

def <<(child)
  if ( child.nil? || !( child.kind_of?(Taskish::Project) || child.kind_of?(Taskish::Task) ) )
    raise(ArgumentError, 'invalid project/task')
  end
  if child.kind_of?(Taskish::Project)
    child.instance_variable_set( :@parent, self )
  end
  @children << child
  self
end

#debug(depth = 0) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/taskish/project.rb', line 52

def debug(depth = 0)
  puts "%s#{ @name }:" % [ '  ' * depth ]
  projects.each { |p| p.debug( depth + 1 ) }
  tasks(false).each do |t|
    puts "%s- #{ t.raw }" % [ '  ' * ( depth + 1 ) ]
  end
end

#projectsObject



60
61
62
# File 'lib/taskish/project.rb', line 60

def projects
  @children.select { |child| child.kind_of? Taskish::Project }
end

#tasks(recurse = true) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/taskish/project.rb', line 64

def tasks(recurse = true)
  if recurse
    return @children.collect { |child| child.kind_of?( Taskish::Project ) ? child.tasks : child }.flatten
  else
    return @children.select { |child| child.kind_of?( Taskish::Task ) }
  end
end

#to_sObject

TODO Include parent information?



73
74
75
# File 'lib/taskish/project.rb', line 73

def to_s
  @parent ? sprintf( "%s: %s" % [ self.parent, @name ] ) : @name
end