Class: Taskish::Project
- Inherits:
-
Object
- Object
- Taskish::Project
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #debug(depth = 0) ⇒ Object
-
#initialize(project) {|_self| ... } ⇒ Project
constructor
A new instance of Project.
- #projects ⇒ Object
- #tasks(recurse = true) ⇒ Object
-
#to_s ⇒ Object
TODO Include parent information?.
Constructor Details
#initialize(project) {|_self| ... } ⇒ Project
Returns a new instance of Project.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/taskish/project.rb', line 32 def name @name end |
#parent ⇒ Object (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 |
#projects ⇒ Object
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_s ⇒ Object
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 |