ardekantur-gantty 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rake'
2
- require 'rake/rdoctask'
2
+ require 'hanna/rdoctask'
3
3
  require 'rake/gempackagetask'
4
4
  require 'rubygems/specification'
5
5
  require 'spec/rake/spectask'
@@ -33,9 +33,9 @@ end
33
33
 
34
34
  desc "generate rdoc documentation"
35
35
  Rake::RDocTask.new(:rdoc) do |rdoc|
36
- rdoc.rdoc_files.include('readme.md', 'LICENSE' ).
36
+ rdoc.rdoc_files.include('readme.rdoc', 'LICENSE' ).
37
37
  include('lib/**/*.rb')
38
38
 
39
- rdoc.main = "readme.md"
39
+ rdoc.main = "readme.rdoc"
40
40
  rdoc.rdoc_dir = 'doc' # rdoc output folder
41
41
  end
@@ -53,12 +53,43 @@ module Gantty
53
53
  return Resource.new(args)
54
54
  end
55
55
 
56
+ def self.create(&block)
57
+ gantt = GanttChart.new
58
+ gantt.instance_eval(&block)
59
+ return gantt
60
+ end
61
+
62
+ def self.create_task(name, &block)
63
+ task = Task.new(name)
64
+ task.instance_eval(&block)
65
+ return task
66
+ end
67
+
56
68
  class GanttChart
57
69
 
58
- attr_accessor :resources, :tasks, :name
70
+ attr_accessor :resources, :tasks
71
+
72
+ def company(set = nil)
73
+ return @company unless set
74
+ @company = set
75
+ end
76
+
77
+ def website set = nil
78
+ return @website unless set
79
+ @website = set
80
+ end
81
+
82
+ def details set = nil
83
+ return @details unless set
84
+ @details = set
85
+ end
86
+
87
+ def name set = nil
88
+ return @name unless set
89
+ @name = set
90
+ end
59
91
 
60
92
  def initialize file = nil
61
- @name = nil
62
93
  @gantt = nil
63
94
  @resources, @tasks = [], []
64
95
  if file
@@ -67,6 +98,12 @@ module Gantty
67
98
  end
68
99
  end
69
100
 
101
+ def task(name, &block)
102
+ task = Task.new(name)
103
+ task.instance_eval(&block)
104
+ @tasks << task
105
+ end
106
+
70
107
  def parse_gantt
71
108
  depends = { 1 => [], 2 => [], 3 => [], 4 => [] }
72
109
  @gantt.xpath('//resource').each { |r| @resources << Resource.new(r) }
@@ -287,7 +324,7 @@ module Gantty
287
324
  class Task
288
325
 
289
326
  attr_accessor :start, :duration, :end
290
- attr_accessor :name, :percent_complete, :coordinators, :priority, :color
327
+ attr_accessor :percent_complete, :coordinators, :priority, :color
291
328
 
292
329
  # The dependency arrays of the task. Dependencies are defined at Task.
293
330
  attr_accessor :starts_with, :starts_after, :finishes_with, :finishes_before
@@ -303,7 +340,7 @@ module Gantty
303
340
  # task = Gantty::Task.new :name => "Create chunky bacon"
304
341
  #
305
342
  # Right now, only specifying <tt>:name</tt> in the hash works.
306
- def initialize t
343
+ def initialize t = nil
307
344
  @notes = nil
308
345
  @starts_with, @starts_after, @finishes_with, @finishes_before, @tasks = [], [], [], [], []
309
346
  if t.is_a? Hash
@@ -406,6 +443,22 @@ module Gantty
406
443
  @finishes_before << t
407
444
  end
408
445
 
446
+ # Attributes
447
+ def name set = nil
448
+ return @name unless set
449
+ @name = set
450
+ end
451
+
452
+ def start set = nil
453
+ return @start unless set
454
+ self.start = set
455
+ end
456
+
457
+ def duration set = nil
458
+ return @duration unless set
459
+ self.duration = set
460
+ end
461
+
409
462
  end
410
463
 
411
464
  class Resource
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "Gantty" do
4
4
 
5
- before do
5
+ setup do
6
6
  @gantt = Gantty::Open GANTT_CHART
7
7
  end
8
8
 
@@ -28,5 +28,49 @@ describe "Gantty" do
28
28
 
29
29
  it "should return itself as correct XML"
30
30
  it "should have a company name"
31
+
32
+ describe "when integrating new tasks with an existing GanttProject file" do
33
+ it "should keep all existing attributes of the GanttProject file"
34
+ it "should not cause collisions between task IDs"
35
+ it "should not cause collisions between resource IDs"
36
+ end
37
+
38
+ describe "when using awesome Rubyish syntax" do
39
+ it "should accept blocks for chart creation" do
40
+
41
+ @gantt = Gantty::create do
42
+ name "Project Alpha Gantt Chart"
43
+ company "Awesomeco, Inc."
44
+ website "http://example.com"
45
+ details "This is the description of the project."
46
+ end
47
+
48
+ @gantt.name.should == "Project Alpha Gantt Chart"
49
+ @gantt.company.should == "Awesomeco, Inc."
50
+ @gantt.website.should == "http://example.com"
51
+ @gantt.details.should == "This is the description of the project."
52
+ end
53
+
54
+ it "should accept blocks for task creation inside a Gantt creation block" do
55
+ @gantt = Gantty::create do
56
+ company "Awesomeco, Inc."
57
+ website "http://example.com"
58
+ details "This is the description of the project."
59
+
60
+ task "Complete this task" do
61
+ start Date.new(2009, 1, 12)
62
+ duration 30
63
+ end
64
+ end
65
+
66
+ @gantt.company.should == "Awesomeco, Inc."
67
+ @gantt.website.should == "http://example.com"
68
+ @gantt.details.should == "This is the description of the project."
69
+
70
+ @gantt.all_tasks.size.should == 1
71
+
72
+ end
73
+
74
+ end
31
75
 
32
76
  end
@@ -1,3 +1,3 @@
1
1
  require File.dirname(__FILE__) + '/../lib/gantty'
2
2
 
3
- GANTT_CHART = File.join(File.dirname(__FILE__), 'test_gantt_project.gan')
3
+ GANTT_CHART = File.join(File.dirname(__FILE__), 'test_gantt_project.gan')
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "Task" do
4
4
 
5
- before do
5
+ setup do
6
6
  @gantt = Gantty::Open GANTT_CHART
7
7
  @task = @gantt.all_tasks.first
8
8
  @team_task = @gantt.task_where :id => 12
@@ -171,5 +171,17 @@ describe "Task" do
171
171
  it "should make sure start and end dates are dates"
172
172
  it "should attempt to parse dates from strings if necessary"
173
173
  it "should return its color"
174
+
175
+ it "should accept blocks for task creation outside a Gantt creation block" do
176
+ @task = Gantty::create_task "Complete this task" do
177
+ start Date.new(2009, 1, 1)
178
+ duration 34
179
+ end
180
+
181
+ @task.name.should == "Complete this task"
182
+ @task.start.should == Date.new(2009, 1, 1)
183
+ @task.duration.should == 34
184
+ @task.end.should == Date.new(2009, 1, 1) + 34
185
+ end
174
186
 
175
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ardekantur-gantty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ardekantur