Class: Gantty::Task

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.



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 343

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
    @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

#colorObject

Returns the value of attribute color.



327
328
329
# File 'lib/gantty.rb', line 327

def color
  @color
end

#coordinatorsObject

Returns the value of attribute coordinators.



327
328
329
# File 'lib/gantty.rb', line 327

def coordinators
  @coordinators
end

#duration(set = nil) ⇒ Object

Returns the value of attribute duration.



326
327
328
# File 'lib/gantty.rb', line 326

def duration
  @duration
end

#endObject

Returns the value of attribute end.



326
327
328
# File 'lib/gantty.rb', line 326

def end
  @end
end

#finishes_beforeObject

The dependency arrays of the task. Dependencies are defined at Task.



330
331
332
# File 'lib/gantty.rb', line 330

def finishes_before
  @finishes_before
end

#finishes_withObject

The dependency arrays of the task. Dependencies are defined at Task.



330
331
332
# File 'lib/gantty.rb', line 330

def finishes_with
  @finishes_with
end

#idObject (readonly)

The GanttProject internal id field for the task.



334
335
336
# File 'lib/gantty.rb', line 334

def id
  @id
end

Returns the value of attribute link.



331
332
333
# File 'lib/gantty.rb', line 331

def link
  @link
end

#notesObject

Returns the value of attribute notes.



331
332
333
# File 'lib/gantty.rb', line 331

def notes
  @notes
end

#percent_completeObject

Returns the value of attribute percent_complete.



327
328
329
# File 'lib/gantty.rb', line 327

def percent_complete
  @percent_complete
end

#priorityObject

Returns the value of attribute priority.



327
328
329
# File 'lib/gantty.rb', line 327

def priority
  @priority
end

#start(set = nil) ⇒ Object

Returns the value of attribute start.



326
327
328
# File 'lib/gantty.rb', line 326

def start
  @start
end

#starts_afterObject

The dependency arrays of the task. Dependencies are defined at Task.



330
331
332
# File 'lib/gantty.rb', line 330

def starts_after
  @starts_after
end

#starts_withObject

The dependency arrays of the task. Dependencies are defined at Task.



330
331
332
# File 'lib/gantty.rb', line 330

def starts_with
  @starts_with
end

#tasksObject

Returns the value of attribute tasks.



331
332
333
# File 'lib/gantty.rb', line 331

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

#name(set = nil) ⇒ Object

Attributes



447
448
449
450
# File 'lib/gantty.rb', line 447

def name set = nil
  return @name unless set
  @name = set
end

#xml_coordinator_propertiesObject



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_propertiesObject



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