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.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#end ⇒ Object
Returns the value of attribute end.
-
#finishes_before ⇒ Object
The dependency arrays of the task.
-
#finishes_with ⇒ Object
The dependency arrays of the task.
-
#id ⇒ Object
readonly
The GanttProject internal
idfield for the task. -
#link ⇒ Object
Returns the value of attribute link.
-
#name ⇒ Object
Returns the value of attribute name.
-
#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.
-
#start ⇒ Object
Returns the value of attribute start.
-
#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 ++.
-
#initialize(t) ⇒ Task
constructor
Create a new task.
- #xml_coordinator_properties ⇒ Object
- #xml_properties ⇒ Object
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
#color ⇒ Object
Returns the value of attribute color.
290 291 292 |
# File 'lib/gantty.rb', line 290 def color @color end |
#coordinators ⇒ Object
Returns the value of attribute coordinators.
290 291 292 |
# File 'lib/gantty.rb', line 290 def coordinators @coordinators end |
#duration ⇒ Object
Returns the value of attribute duration.
289 290 291 |
# File 'lib/gantty.rb', line 289 def duration @duration end |
#end ⇒ Object
Returns the value of attribute end.
289 290 291 |
# File 'lib/gantty.rb', line 289 def end @end end |
#finishes_before ⇒ Object
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_with ⇒ Object
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 |
#id ⇒ Object (readonly)
The GanttProject internal id field for the task.
297 298 299 |
# File 'lib/gantty.rb', line 297 def id @id end |
#link ⇒ Object
Returns the value of attribute link.
294 295 296 |
# File 'lib/gantty.rb', line 294 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
290 291 292 |
# File 'lib/gantty.rb', line 290 def name @name end |
#notes ⇒ Object
Returns the value of attribute notes.
294 295 296 |
# File 'lib/gantty.rb', line 294 def notes @notes end |
#percent_complete ⇒ Object
Returns the value of attribute percent_complete.
290 291 292 |
# File 'lib/gantty.rb', line 290 def percent_complete @percent_complete end |
#priority ⇒ Object
Returns the value of attribute priority.
290 291 292 |
# File 'lib/gantty.rb', line 290 def priority @priority end |
#start ⇒ Object
Returns the value of attribute start.
289 290 291 |
# File 'lib/gantty.rb', line 289 def start @start end |
#starts_after ⇒ Object
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_with ⇒ Object
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 |
#tasks ⇒ Object
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_properties ⇒ Object
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_properties ⇒ Object
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 |