Class: Gantty::Task
- Inherits:
-
Object
- Object
- Gantty::Task
- Defined in:
- lib/gantty.rb
Overview
A Task is a single Gantt chart item. It has several editable properties, as well as relationships with other tasks.
Properties
- name
-
The description of the task.
- start
-
The start date of the task. Accepts DateTime objects.
- end
-
The end date of the task. Accepts DateTime objects.
- duration
-
The duration, in days, of the task.
- percent_complete
-
The percentage complete of the task. Accepts integers from 0 to 100.
- priority
-
The importance of the task. Accepts one of
[:low, :medium, :high]
. - color
-
The color of the task in GanttProject. Accepts RGB hex triplets (such as “#391204”)
- notes
-
Notes for the task.
- link
-
A hyperlink related to the task.
Coordinators
Coordinators are people working on a task. They are defined as instances of the Resource class. Coordinators are added to Tasks by specifying the instance, for now. This is done with #add_resource:
@task.add_resource Gantty::Resource "Adam Alpha"
Dependencies
A dependency is a relationship between one task and another. They are defined as follows:
-
Start->Start: Both tasks start at the same time. Accessed as #starts_with.
-
Start->Finish: The current task finishes as the referenced task begins. Accessed as #finishes_before.
-
Finish->Start: The current task starts as the referenced task ends. Accessed as #starts_after.
-
Finish->Finish: Both tasks end at the same time. Accessed as #finishes_with.
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#coordinators ⇒ Object
Returns the value of attribute coordinators.
-
#finishes_before ⇒ Object
The dependency arrays of the task.
-
#finishes_with ⇒ Object
The dependency arrays of the task.
-
#id ⇒ Object
readonly
The GanttProject internal
id
field for the task. -
#link ⇒ Object
Returns the value of attribute link.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#percent_complete ⇒ Object
Returns the value of attribute percent_complete.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#starts_after ⇒ Object
The dependency arrays of the task.
-
#starts_with ⇒ Object
The dependency arrays of the task.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Instance Method Summary collapse
- #add_finishes_before(t) ⇒ Object
- #add_finishes_with(t) ⇒ Object
- #add_resource(resource) ⇒ Object
- #add_starts_after(t) ⇒ Object
-
#add_starts_with(t) ⇒ Object
– If Task B has predecessor Task A with relationship Finish->Start, task_b.before.include? task_a <task id=“#task_atask_a.id”…><depend id=“#task_btask_b.id” type=“2” difference=“1” hardness=“Rubber”/></task> Start-Start: 1 => #starts_with Finish-Start: 2 => #starts_after Finish-Finish: 3 => #finishes_with Start-Finish: 4 => #finishes_before ++.
-
#duration=(new_duration) ⇒ Object
Set the duration of the task.
-
#end=(new_date) ⇒ Object
Set the end date of the task.
-
#initialize(t = nil) ⇒ Task
constructor
Create a new task.
-
#start=(new_date) ⇒ Object
Set the start date of the task.
- #xml_coordinator_properties ⇒ Object
- #xml_properties ⇒ Object
Constructor Details
#initialize(t = nil) ⇒ Task
Create a new task. t
can be a hash of options, the name
of the task, or a Nokogiri node containing a task element of a GanttProject file. Most people will only use the first two options.
task = Gantty::Task.new "Create chunky bacon"
task = Gantty::Task.new :name => "Create chunky bacon"
Right now, only specifying :name
in the hash works.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/gantty.rb', line 342 def initialize t = nil @notes = nil @starts_with, @starts_after, @finishes_with, @finishes_before, @tasks = [], [], [], [], [] if t.is_a? Hash @name = t[:name] elsif t.is_a? String raise ArgumentError, "name cannot be blank" if t.length == 0 @name = t else # This is when we're probably getting a Nokogiri object, so attempt to parse that. @name = t.attributes["name"] @start = Date.strptime(t.attributes["start"]) @duration = t.attributes["duration"].to_i @priority = PRIORITY[t.attributes["priority"].to_i] @end = @start + @duration @percent_complete = t.attributes["complete"].to_i @coordinators = [] @color = t.attributes["color"] @id = t.attributes["id"].to_i @link = (t.attributes.include?("webLink") ? t.attributes["webLink"] : nil) t.children.select { |c| c.name == "notes" }.each do |note| @notes = note.inner_text end end end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
326 327 328 |
# File 'lib/gantty.rb', line 326 def color @color end |
#coordinators ⇒ Object
Returns the value of attribute coordinators.
326 327 328 |
# File 'lib/gantty.rb', line 326 def coordinators @coordinators end |
#finishes_before ⇒ Object
The dependency arrays of the task. Dependencies are defined at Task.
329 330 331 |
# File 'lib/gantty.rb', line 329 def finishes_before @finishes_before end |
#finishes_with ⇒ Object
The dependency arrays of the task. Dependencies are defined at Task.
329 330 331 |
# File 'lib/gantty.rb', line 329 def finishes_with @finishes_with end |
#id ⇒ Object (readonly)
The GanttProject internal id
field for the task.
333 334 335 |
# File 'lib/gantty.rb', line 333 def id @id end |
#link ⇒ Object
Returns the value of attribute link.
330 331 332 |
# File 'lib/gantty.rb', line 330 def link @link end |
#notes ⇒ Object
Returns the value of attribute notes.
330 331 332 |
# File 'lib/gantty.rb', line 330 def notes @notes end |
#percent_complete ⇒ Object
Returns the value of attribute percent_complete.
326 327 328 |
# File 'lib/gantty.rb', line 326 def percent_complete @percent_complete end |
#priority ⇒ Object
Returns the value of attribute priority.
326 327 328 |
# File 'lib/gantty.rb', line 326 def priority @priority end |
#starts_after ⇒ Object
The dependency arrays of the task. Dependencies are defined at Task.
329 330 331 |
# File 'lib/gantty.rb', line 329 def starts_after @starts_after end |
#starts_with ⇒ Object
The dependency arrays of the task. Dependencies are defined at Task.
329 330 331 |
# File 'lib/gantty.rb', line 329 def starts_with @starts_with end |
#tasks ⇒ Object
Returns the value of attribute tasks.
330 331 332 |
# File 'lib/gantty.rb', line 330 def tasks @tasks end |
Instance Method Details
#add_finishes_before(t) ⇒ Object
442 443 444 |
# File 'lib/gantty.rb', line 442 def add_finishes_before t @finishes_before << t end |
#add_finishes_with(t) ⇒ Object
438 439 440 |
# File 'lib/gantty.rb', line 438 def add_finishes_with t @finishes_with << t end |
#add_resource(resource) ⇒ Object
368 369 370 |
# File 'lib/gantty.rb', line 368 def add_resource resource (@coordinators ||= []) << resource end |
#add_starts_after(t) ⇒ Object
434 435 436 |
# File 'lib/gantty.rb', line 434 def add_starts_after t @starts_after << t end |
#add_starts_with(t) ⇒ Object
– If Task B has predecessor Task A with relationship Finish->Start, task_b.before.include? task_a <task id=“#Gantty::Task.task_atask_a.id”…><depend id=“#Gantty::Task.task_btask_b.id” type=“2” difference=“1” hardness=“Rubber”/></task> Start-Start: 1 => #starts_with Finish-Start: 2 => #starts_after Finish-Finish: 3 => #finishes_with Start-Finish: 4 => #finishes_before ++
430 431 432 |
# File 'lib/gantty.rb', line 430 def add_starts_with t @starts_with << t end |
#duration=(new_duration) ⇒ Object
Set the duration of the task. If a start date has been specified, the end date will be set to (start + duration). If a start date has not been specified, today is used.
390 391 392 393 394 395 396 |
# File 'lib/gantty.rb', line 390 def duration= new_duration raise ArgumentError, "expected a number of days" unless new_duration.is_a? Fixnum raise ArgumentError, "expected a positive day count" if new_duration < 0 @start = Date.today unless @start @duration = new_duration @end = @start + new_duration end |
#end=(new_date) ⇒ Object
Set the end date of the task. The duration is updated if an end date has already been specified.
381 382 383 384 385 386 |
# File 'lib/gantty.rb', line 381 def end= new_date raise ArgumentError, "expected a DateTime" unless new_date.is_a? Date raise ArgumentError, "end date cannot be before start date" if @start and new_date <= @start @end = new_date @duration = (@end - @start).to_i if @start end |
#start=(new_date) ⇒ Object
Set the start date of the task. The duration is updated if an end date has already been specified.
373 374 375 376 377 378 |
# File 'lib/gantty.rb', line 373 def start= new_date raise ArgumentError, "expected a DateTime" unless new_date.is_a? Date raise ArgumentError, "start date cannot be past end date" if @end and new_date >= @end @start = new_date @duration = (@end - @start).to_i if @end end |
#xml_coordinator_properties ⇒ Object
412 413 414 415 416 417 418 419 |
# File 'lib/gantty.rb', line 412 def xml_coordinator_properties res = [] return res unless @coordinators @coordinators.each do |coordinator| res << {"task-id" => id, "resource-id" => coordinator.id, :function => "Default:0", :responsible => true, :load => 100.0 } end return res end |
#xml_properties ⇒ Object
405 406 407 408 409 410 |
# File 'lib/gantty.rb', line 405 def xml_properties properties = { :id => id, :name => name, :color => color, :meeting => false, :start => start.strftime("%Y-%m-%d"), :duration => duration, :complete => percent_complete, :priority => PRIORITY[priority], :expand => false } properties.merge!( :webLink => @link ) if @link return properties end |