ardekantur-gantty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'spec/rake/spectask'
5
+
6
+ task :default => :spec
7
+
8
+ desc "Run all specs"
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ t.spec_files = FileList['spec/*.rb']
11
+ t.spec_opts = ['--color']
12
+ end
13
+
14
+ spec = Gem::Specification.load('gantty.gemspec')
15
+
16
+ Rake::GemPackageTask.new(spec) do |pkg|
17
+ pkg.gem_spec = spec
18
+ end
19
+
20
+ desc "install the gem locally"
21
+ task :install => [:package] do
22
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
23
+ end
data/lib/gantty.rb ADDED
@@ -0,0 +1,80 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'rubygems'
4
+ require 'nokogiri'
5
+
6
+ module Gantty
7
+
8
+ def self.Open file
9
+ return GanttChart.new(file)
10
+ end
11
+
12
+ class GanttChart
13
+
14
+ attr_accessor :resources, :tasks
15
+
16
+ def initialize file = nil
17
+ @gantt = nil
18
+ @resources, @tasks = [], []
19
+ if file
20
+ @gantt = Nokogiri::XML(open(File.expand_path(file)))
21
+ parse_gantt
22
+ end
23
+ end
24
+
25
+ def parse_gantt
26
+ @gantt.xpath('//resource').each { |r| @resources << Resource.new(r) }
27
+ @gantt.xpath('//task').each { |t| @tasks << Task.new(t) }
28
+ @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 } } }
29
+ end
30
+
31
+ def current_tasks date = Date.today
32
+ @tasks.select { |t| t.start < date and t.end > date }
33
+ end
34
+
35
+ end
36
+
37
+ class Task
38
+ attr_accessor :name, :start, :duration, :end, :percent_complete, :coordinators
39
+ attr_reader :id
40
+
41
+ def initialize t
42
+ @name = t.attributes["name"]
43
+ @start = Date.strptime(t.attributes["start"])
44
+ @duration = t.attributes["duration"].to_i
45
+ @end = @start + @duration
46
+ @percent_complete = t.attributes["complete"]
47
+ @coordinators = []
48
+ @id = t.attributes["id"].to_i
49
+ end
50
+
51
+ def start= new_date
52
+ raise ArgumentError, "expected a DateTime" unless new_date.is_a? Date
53
+ raise ArgumentError, "start date cannot be past end date" unless new_date <= @end
54
+ @start = new_date
55
+ @duration = (@end - @start).to_i
56
+ end
57
+
58
+ def end= new_date
59
+ raise ArgumentError, "expected a DateTime" unless new_date.is_a? Date
60
+ raise ArgumentError, "end date cannot be before start date" unless new_date >= @start
61
+ @end = new_date
62
+ @duration = (@end - @start).to_i
63
+ end
64
+
65
+ end
66
+
67
+ class Resource
68
+ attr_accessor :name, :email, :phone
69
+ attr_reader :id
70
+
71
+ def initialize r
72
+ @name = r.attributes["name"]
73
+ @phone = r.attributes["phone"]
74
+ @email = r.attributes["contacts"]
75
+ @id = r.attributes["id"].to_i
76
+ end
77
+
78
+ end
79
+
80
+ end
data/spec/design.yml ADDED
@@ -0,0 +1,19 @@
1
+ Gantty:
2
+ - should return a list of all resources
3
+ - should return a list of all tasks
4
+ - should return a list of all allocations
5
+ - should return a list of all current tasks
6
+
7
+ Resource:
8
+ - should have a name
9
+ - should have an e-mail address
10
+ - should have a phone number
11
+
12
+ Task:
13
+ - should have a name
14
+ - should have a start date
15
+ - should have a duration
16
+ - should have an end date
17
+ - should change the duration to match a changed end date
18
+ - should change the duration to match a changed start date
19
+ - should return an array of coordinators
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Gantty" do
4
+
5
+ before do
6
+ @gantt = Gantty::Open GANTT_CHART
7
+ end
8
+
9
+ it "should return a list of all resources" do
10
+ @gantt.resources.size.should == 4
11
+ end
12
+
13
+ it "should return a list of all tasks" do
14
+ @gantt.tasks.size.should == 37
15
+ end
16
+
17
+ it "should return a list of all current tasks" do
18
+ @gantt.current_tasks(Date.new(2008, 10, 18)).size.should == 9
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Resource" do
4
+
5
+ before do
6
+ @gantt = Gantty::Open GANTT_CHART
7
+ end
8
+
9
+ it "should have a name" do
10
+ @gantt.resources.first.name.should == "Adam Alpha"
11
+ end
12
+
13
+ it "should have an e-mail address" do
14
+ @gantt.resources.first.email.should == "adam.alpha@gmail.com"
15
+ end
16
+
17
+ it "should have a phone number" do
18
+ @gantt.resources.first.phone.should == "555-555-0123"
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ require File.dirname(__FILE__) + '/../lib/gantty'
2
+
3
+ GANTT_CHART = File.join(File.dirname(__FILE__), 'test_gantt_project.gan')
data/spec/task_spec.rb ADDED
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Task" do
4
+
5
+ before do
6
+ @gantt = Gantty::Open GANTT_CHART
7
+ @task = @gantt.tasks.first
8
+ @team_task = @gantt.tasks.select { |t| t.id == 20 }.first
9
+ end
10
+
11
+ it "should have a name" do
12
+ @task.name.should == "Project Planning"
13
+ end
14
+
15
+ it "should have a start date" do
16
+ @task.start.month.should == 10
17
+ @task.start.year.should == 2008
18
+ @task.start.day.should == 14
19
+ end
20
+
21
+ it "should have a duration" do
22
+ @task.duration.should == 161
23
+ end
24
+
25
+ it "should have an end date" do
26
+ @task.end.should == @task.start + @task.duration
27
+ end
28
+
29
+ it "should change the duration to match a changed end date" do
30
+ @task.end = Date.new(2008,10, 30)
31
+ @task.duration.should == 16
32
+ end
33
+
34
+ it "should not allow an end date that comes before the start date" do
35
+ @task.start = Date.new(2008,10, 10)
36
+ @task.duration.should == 165
37
+ end
38
+
39
+ it "should not allow a start date that comes before the end date" do
40
+ lambda { @task.end = Date.new(2008, 10, 10) }.should raise_error ArgumentError
41
+ end
42
+
43
+ it "should change the duration to match a changed start date" do
44
+ lambda { @task.start = Date.new(2009, 10, 1) }.should raise_error ArgumentError
45
+ end
46
+
47
+ it "should return an array of coordinators" do
48
+ @team_task.coordinators.size.should == 2
49
+ @team_task.coordinators.first.name.should == "Bob Beta"
50
+ end
51
+
52
+ end
@@ -0,0 +1,124 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project name="ClementineGantt" company="" webLink="" view-date="2008-10-12" view-index="1" gantt-divider-location="652" resource-divider-location="301" version="2.0">
3
+ <description></description>
4
+ <view zooming-state="default:4" id="gantt-chart"/>
5
+ <view id="resource-table">
6
+ <field id="0" name="Name" width="55" order="0"/>
7
+ <field id="1" name="Default role" width="44" order="1"/>
8
+ </view>
9
+ <!-- -->
10
+ <calendars>
11
+ <day-types>
12
+ <day-type id="0"/>
13
+ <day-type id="1"/>
14
+ <calendar id="1" name="default">
15
+ <default-week sun="0" mon="0" tue="0" wed="0" thu="0" fri="0" sat="0"/>
16
+ <overriden-day-types/>
17
+ <days/>
18
+ </calendar>
19
+ </day-types>
20
+ </calendars>
21
+ <tasks color="#8cb6ce">
22
+ <taskproperties>
23
+ <taskproperty id="tpd0" name="type" type="default" valuetype="icon"/>
24
+ <taskproperty id="tpd1" name="priority" type="default" valuetype="icon"/>
25
+ <taskproperty id="tpd2" name="info" type="default" valuetype="icon"/>
26
+ <taskproperty id="tpd3" name="name" type="default" valuetype="text"/>
27
+ <taskproperty id="tpd4" name="begindate" type="default" valuetype="date"/>
28
+ <taskproperty id="tpd5" name="enddate" type="default" valuetype="date"/>
29
+ <taskproperty id="tpd6" name="duration" type="default" valuetype="int"/>
30
+ <taskproperty id="tpd7" name="completion" type="default" valuetype="int"/>
31
+ <taskproperty id="tpd8" name="coordinator" type="default" valuetype="text"/>
32
+ <taskproperty id="tpd9" name="predecessorsr" type="default" valuetype="text"/>
33
+ </taskproperties>
34
+ <task id="0" name="Project Planning" color="#8cb6ce" meeting="false" start="2008-10-14" duration="161" complete="13" priority="1" expand="true">
35
+ <task id="1" name="Research" color="#8cb6ce" meeting="false" start="2008-10-14" duration="13" complete="47" priority="1" expand="true">
36
+ <task id="2" name="Existing Tech" color="#8cb6ce" meeting="false" start="2008-10-14" duration="6" complete="0" priority="1" expand="true"/>
37
+ <task id="3" name="User testing" color="#8cb6ce" meeting="false" start="2008-10-14" duration="6" complete="0" priority="1" expand="true">
38
+ <notes><![CDATA[investigate how to get this into the hands of a student in a game class during term 2 or 3]]></notes>
39
+ </task>
40
+ <task id="4" name="Hardware Driver Libs" color="#8cb6ce" meeting="false" start="2008-10-14" duration="6" complete="0" priority="1" expand="true"/>
41
+ <task id="5" name="Gesture/Helper libs" color="#8cb6ce" meeting="false" start="2008-10-14" duration="6" complete="0" priority="1" expand="true"/>
42
+ <task id="6" name="Wii Homebrew" color="#8cb6ce" meeting="false" start="2008-10-14" duration="6" complete="75" priority="1" expand="true"/>
43
+ <task id="7" name="COM bridge between C++ and C#" color="#8cb6ce" meeting="false" start="2008-10-14" duration="13" complete="100" priority="1" expand="true"/>
44
+ <task id="8" name="Google group/interproject communication" color="#8cb6ce" meeting="false" start="2008-10-14" duration="6" complete="100" priority="1" expand="true"/>
45
+ </task>
46
+ <task id="9" name="Formalization of Project" color="#8cb6ce" meeting="false" start="2008-10-22" duration="10" complete="42" priority="1" expand="true"/>
47
+ <task id="10" name="Website" color="#8cb6ce" meeting="false" start="2008-11-03" duration="141" complete="8" priority="1" expand="true"/>
48
+ </task>
49
+ <task id="11" name="Project planning and design" color="#8cb6ce" meeting="false" start="2008-10-27" duration="102" complete="1" priority="1" expand="true">
50
+ <task id="33" name="UML" color="#ff0033" meeting="false" start="2008-10-27" duration="7" complete="0" priority="1" expand="true">
51
+ <task id="34" name="3D Wiimote Interface" color="#ff0033" meeting="false" start="2008-10-27" duration="7" complete="0" priority="1" expand="true"/>
52
+ <task id="35" name="Spatial Interface" color="#ff0033" meeting="false" start="2008-10-27" duration="7" complete="0" priority="1" expand="true"/>
53
+ <task id="36" name="3D input wiimote service providers" color="#ff0033" meeting="false" start="2008-10-27" duration="7" complete="0" priority="1" expand="true"/>
54
+ </task>
55
+ <task id="12" name="Requirements Doc" color="#ff3333" meeting="false" start="2008-11-03" duration="16" complete="7" priority="1" expand="true"/>
56
+ <task id="13" name="Acceptance Test Plan" color="#ff3333" meeting="false" start="2008-11-17" duration="12" complete="0" priority="1" expand="true"/>
57
+ <task id="14" name="Design Document" color="#ff3333" meeting="false" start="2008-12-02" duration="45" complete="0" priority="1" expand="true"/>
58
+ <task id="15" name="Integration Test Plan" color="#ff3333" meeting="false" start="2009-01-26" duration="11" complete="0" priority="1" expand="true"/>
59
+ </task>
60
+ <task id="16" name="Implementation" color="#8cb6ce" meeting="false" start="2009-01-01" duration="77" complete="0" priority="1" expand="true">
61
+ <task id="17" name="Core" color="#00ff00" meeting="false" start="2009-01-01" duration="77" complete="0" priority="1" expand="true"/>
62
+ <task id="18" name="Interfaces" color="#8cb6ce" meeting="false" start="2009-01-01" duration="52" complete="0" priority="1" expand="true">
63
+ <task id="19" name="3D Interface" color="#00ff00" meeting="false" start="2009-01-01" duration="52" complete="0" priority="1" expand="true"/>
64
+ <task id="20" name="Spatial Interface" color="#00ff00" meeting="false" start="2009-01-01" duration="52" complete="0" priority="1" expand="true"/>
65
+ <task id="21" name="Accelerometer Interface" color="#00ff00" meeting="false" start="2009-01-01" duration="52" complete="0" priority="1" expand="true"/>
66
+ </task>
67
+ <task id="22" name="Demos" color="#8cb6ce" meeting="false" start="2009-02-16" duration="31" complete="0" priority="1" expand="true">
68
+ <task id="23" name="3D Demo" color="#00ff00" meeting="false" start="2009-02-16" duration="31" complete="0" priority="1" expand="true"/>
69
+ <task id="24" name="Spatial Demo" color="#00ff00" meeting="false" start="2009-02-16" duration="31" complete="0" priority="1" expand="true"/>
70
+ <task id="25" name="Tennis Demo" color="#00ff00" meeting="false" start="2009-02-16" duration="31" complete="0" priority="1" expand="true"/>
71
+ </task>
72
+ </task>
73
+ <task id="26" name="Testing" color="#8cb6ce" meeting="false" start="2008-12-01" duration="142" complete="0" priority="1" expand="true">
74
+ <task id="27" name="Writing acceptance Tests" color="#990099" meeting="false" start="2008-12-01" duration="31" complete="0" priority="1" expand="true"/>
75
+ <task id="28" name="Perform test on new code" color="#990099" meeting="false" start="2009-01-01" duration="90" complete="0" priority="1" expand="true"/>
76
+ <task id="29" name="Tests and bug fixes" color="#990099" meeting="false" start="2009-04-01" duration="21" complete="0" priority="1" expand="true"/>
77
+ </task>
78
+ <task id="30" name="Presentation Prep" color="#8cb6ce" meeting="false" start="2009-01-20" duration="103" complete="0" priority="1" expand="true">
79
+ <task id="31" name="Initial presentations" color="#ffcc33" meeting="false" start="2009-01-20" duration="5" complete="0" priority="1" expand="true"/>
80
+ <task id="32" name="Final Presentations" color="#ffcc33" meeting="false" start="2009-04-27" duration="6" complete="0" priority="1" expand="true"/>
81
+ </task>
82
+ </tasks>
83
+ <resources>
84
+ <resource id="6" name="Adam Alpha" function="Default:1" contacts="adam.alpha@gmail.com" phone="555-555-0123"/>
85
+ <resource id="7" name="Bob Beta" function="Default:0" contacts="bob.beta@gmail.com" phone="555-555-1234"/>
86
+ <resource id="8" name="Dave Delta" function="Default:0" contacts="dave.delta@gmail.com" phone="555-555-2345"/>
87
+ <resource id="9" name="Ed Epsilon" function="Default:0" contacts="ed.epsilon@gmail.com" phone="555-555-3456"/>
88
+ </resources>
89
+ <allocations>
90
+ <allocation task-id="2" resource-id="8" function="Default:0" responsible="true" load="100.0"/>
91
+ <allocation task-id="4" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
92
+ <allocation task-id="5" resource-id="9" function="Default:0" responsible="true" load="100.0"/>
93
+ <allocation task-id="6" resource-id="9" function="Default:0" responsible="true" load="100.0"/>
94
+ <allocation task-id="7" resource-id="6" function="Default:1" responsible="true" load="100.0"/>
95
+ <allocation task-id="8" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
96
+ <allocation task-id="10" resource-id="9" function="Default:0" responsible="false" load="100.0"/>
97
+ <allocation task-id="10" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
98
+ <allocation task-id="34" resource-id="9" function="Default:0" responsible="true" load="100.0"/>
99
+ <allocation task-id="35" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
100
+ <allocation task-id="36" resource-id="6" function="Default:1" responsible="true" load="100.0"/>
101
+ <allocation task-id="12" resource-id="6" function="Default:1" responsible="true" load="100.0"/>
102
+ <allocation task-id="13" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
103
+ <allocation task-id="14" resource-id="6" function="Default:1" responsible="true" load="100.0"/>
104
+ <allocation task-id="15" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
105
+ <allocation task-id="17" resource-id="9" function="Default:0" responsible="false" load="100.0"/>
106
+ <allocation task-id="17" resource-id="7" function="Default:0" responsible="false" load="100.0"/>
107
+ <allocation task-id="17" resource-id="6" function="Default:1" responsible="true" load="100.0"/>
108
+ <allocation task-id="17" resource-id="8" function="Default:0" responsible="false" load="100.0"/>
109
+ <allocation task-id="19" resource-id="8" function="Default:0" responsible="true" load="100.0"/>
110
+ <allocation task-id="20" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
111
+ <allocation task-id="20" resource-id="6" function="Default:1" responsible="true" load="100.0"/>
112
+ <allocation task-id="21" resource-id="7" function="Default:0" responsible="true" load="100.0"/>
113
+ <allocation task-id="23" resource-id="9" function="Default:0" responsible="true" load="100.0"/>
114
+ </allocations>
115
+ <vacations/>
116
+ <taskdisplaycolumns>
117
+ <displaycolumn property-id="tpd3" order="0" width="172"/>
118
+ <displaycolumn property-id="tpd4" order="1" width="27"/>
119
+ <displaycolumn property-id="tpd5" order="2" width="26"/>
120
+ <displaycolumn property-id="tpd8" order="3" width="75"/>
121
+ </taskdisplaycolumns>
122
+ <previous/>
123
+ <roles roleset-name="Default"/>
124
+ </project>
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ardekantur-gantty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ardekantur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-31 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.2
23
+ version:
24
+ description: read ( + write? ) gantt project xml files
25
+ email: greystone@ardekantur.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - README.md
34
+ - Rakefile
35
+ - lib/gantty.rb
36
+ - spec/design.yml
37
+ - spec/gantty_spec.rb
38
+ - spec/resource_spec.rb
39
+ - spec/spec_helper.rb
40
+ - spec/task_spec.rb
41
+ - spec/test_gantt_project.gan
42
+ has_rdoc: false
43
+ homepage: http://github.com/ardekantur/gantty
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: read ( + write? ) gantt project xml files
68
+ test_files:
69
+ - spec/gantty_spec.rb
70
+ - spec/resource_spec.rb
71
+ - spec/task_spec.rb