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) ⇒ 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.



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/gantty.rb', line 306

def initialize t
  @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.



290
291
292
# File 'lib/gantty.rb', line 290

def color
  @color
end

#coordinatorsObject

Returns the value of attribute coordinators.



290
291
292
# File 'lib/gantty.rb', line 290

def coordinators
  @coordinators
end

#durationObject

Returns the value of attribute duration.



289
290
291
# File 'lib/gantty.rb', line 289

def duration
  @duration
end

#endObject

Returns the value of attribute end.



289
290
291
# File 'lib/gantty.rb', line 289

def end
  @end
end

#finishes_beforeObject

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



293
294
295
# File 'lib/gantty.rb', line 293

def finishes_before
  @finishes_before
end

#finishes_withObject

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



293
294
295
# File 'lib/gantty.rb', line 293

def finishes_with
  @finishes_with
end

#idObject (readonly)

The GanttProject internal id field for the task.



297
298
299
# File 'lib/gantty.rb', line 297

def id
  @id
end

Returns the value of attribute link.



294
295
296
# File 'lib/gantty.rb', line 294

def link
  @link
end

#nameObject

Returns the value of attribute name.



290
291
292
# File 'lib/gantty.rb', line 290

def name
  @name
end

#notesObject

Returns the value of attribute notes.



294
295
296
# File 'lib/gantty.rb', line 294

def notes
  @notes
end

#percent_completeObject

Returns the value of attribute percent_complete.



290
291
292
# File 'lib/gantty.rb', line 290

def percent_complete
  @percent_complete
end

#priorityObject

Returns the value of attribute priority.



290
291
292
# File 'lib/gantty.rb', line 290

def priority
  @priority
end

#startObject

Returns the value of attribute start.



289
290
291
# File 'lib/gantty.rb', line 289

def start
  @start
end

#starts_afterObject

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



293
294
295
# File 'lib/gantty.rb', line 293

def starts_after
  @starts_after
end

#starts_withObject

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



293
294
295
# File 'lib/gantty.rb', line 293

def starts_with
  @starts_with
end

#tasksObject

Returns the value of attribute tasks.



294
295
296
# File 'lib/gantty.rb', line 294

def tasks
  @tasks
end

Instance Method Details

#add_finishes_before(t) ⇒ Object



405
406
407
# File 'lib/gantty.rb', line 405

def add_finishes_before t
  @finishes_before << t
end

#add_finishes_with(t) ⇒ Object



401
402
403
# File 'lib/gantty.rb', line 401

def add_finishes_with t
  @finishes_with << t
end

#add_resource(resource) ⇒ Object



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

def add_resource resource
  (@coordinators ||= []) << resource
end

#add_starts_after(t) ⇒ Object



397
398
399
# File 'lib/gantty.rb', line 397

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



393
394
395
# File 'lib/gantty.rb', line 393

def add_starts_with t
  @starts_with << t
end

#xml_coordinator_propertiesObject



375
376
377
378
379
380
381
382
# File 'lib/gantty.rb', line 375

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



368
369
370
371
372
373
# File 'lib/gantty.rb', line 368

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