Class: Gantty::GanttChart

Inherits:
Object
  • Object
show all
Defined in:
lib/gantty.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ GanttChart

Returns a new instance of GanttChart.



16
17
18
19
20
21
22
23
# File 'lib/gantty.rb', line 16

def initialize file = nil
  @gantt = nil
  @resources, @tasks = [], []
  if file
    @gantt = Nokogiri::XML(open(File.expand_path(file)))
    parse_gantt
  end
end

Instance Attribute Details

#resourcesObject

Returns the value of attribute resources.



14
15
16
# File 'lib/gantty.rb', line 14

def resources
  @resources
end

#tasksObject

Returns the value of attribute tasks.



14
15
16
# File 'lib/gantty.rb', line 14

def tasks
  @tasks
end

Instance Method Details

#current_tasks(date = Date.today) ⇒ Object



31
32
33
# File 'lib/gantty.rb', line 31

def current_tasks date = Date.today
  @tasks.select { |t| t.start <= date and t.end >= date }
end

#parse_ganttObject



25
26
27
28
29
# File 'lib/gantty.rb', line 25

def parse_gantt
  @gantt.xpath('//resource').each { |r| @resources << Resource.new(r) }
  @gantt.xpath('//task').each { |t| @tasks << Task.new(t) }
  @tasks.each { |task| @gantt.xpath("//allocation[@task-id=#{task.id}]").each { |alloc| task.coordinators += @resources.select { |r| r.id == alloc.attributes["resource-id"].to_i } } }
end