Class: DevFlow::RoadMap
- Inherits:
-
Object
- Object
- DevFlow::RoadMap
- Defined in:
- lib/dev_flow/roadmap.rb
Overview
a road map represents a list of tasks
Instance Attribute Summary collapse
-
#branch_tasks ⇒ Object
Returns the value of attribute branch_tasks.
-
#config ⇒ Object
Returns the value of attribute config.
-
#file ⇒ Object
Returns the value of attribute file.
-
#ln_tasks ⇒ Object
Returns the value of attribute ln_tasks.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
-
#top_tasks ⇒ Object
Returns the value of attribute top_tasks.
Instance Method Summary collapse
-
#find_parent(level) ⇒ Object
the last task in row that less than the given level is parent task.
-
#initialize(file, config) ⇒ RoadMap
constructor
A new instance of RoadMap.
- #last_task ⇒ Object
- #parse(file = nil) ⇒ Object
- #rewrite!(task_hash) ⇒ Object
- #team_member_names ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(file, config) ⇒ RoadMap
Returns a new instance of RoadMap.
9 10 11 12 13 14 15 |
# File 'lib/dev_flow/roadmap.rb', line 9 def initialize file, config @file, @config = file, config @tasks = Array.new @branch_tasks = Hash.new @ln_tasks = Hash.new @top_tasks = Array.new end |
Instance Attribute Details
#branch_tasks ⇒ Object
Returns the value of attribute branch_tasks.
4 5 6 |
# File 'lib/dev_flow/roadmap.rb', line 4 def branch_tasks @branch_tasks end |
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/dev_flow/roadmap.rb', line 4 def config @config end |
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/dev_flow/roadmap.rb', line 4 def file @file end |
#ln_tasks ⇒ Object
Returns the value of attribute ln_tasks.
4 5 6 |
# File 'lib/dev_flow/roadmap.rb', line 4 def ln_tasks @ln_tasks end |
#tasks ⇒ Object
Returns the value of attribute tasks.
4 5 6 |
# File 'lib/dev_flow/roadmap.rb', line 4 def tasks @tasks end |
#top_tasks ⇒ Object
Returns the value of attribute top_tasks.
4 5 6 |
# File 'lib/dev_flow/roadmap.rb', line 4 def top_tasks @top_tasks end |
Instance Method Details
#find_parent(level) ⇒ Object
the last task in row that less than the given level is parent task
92 93 94 95 |
# File 'lib/dev_flow/roadmap.rb', line 92 def find_parent level self.tasks.reverse.each { |t| return t if t.level < level } nil end |
#last_task ⇒ Object
17 18 19 |
# File 'lib/dev_flow/roadmap.rb', line 17 def last_task @tasks.last end |
#parse(file = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dev_flow/roadmap.rb', line 35 def parse file = nil self.file = file if file fh = File.open(self.file, "r:utf-8") head_part = "" in_header = 0 fh.each do |line| if /^\%\s*\-\-\-+/ =~ line in_header += 1 next end # before any task defined, parse line begin with % as head field: if in_header == 1 and @tasks.size == 0 head_part += line end if /^\s*\[(?<plus_>[\+\s]+)\]\s(?<contents_>.+)/ =~ line if @tasks.size == 0 and head_part.size > 0 hhash = YAML.load(head_part) members = @config["members"] || {} members.merge!(hhash["members"]) if hhash["members"] and hhash["members"].is_a?(Hash) @config = @config.merge hhash @config["members"] = members end line.chomp! task = Task.new(plus_.to_s.count("+"), self.file, $.).parse(contents_, @config) task.validate! # raise for format errors raise "branch name #{task.branch_name} already used on #{self.file}:#{self.branch_tasks[task.branch_name].ln}" if self.branch_tasks[task.branch_name] if task.is_a?(Task) # find perant for the task: parent = self.find_parent task.level if parent parent.children << task task.parent = parent # task.id = (sprintf "%d%d", parent.id, parent.child_number).to_i end @tasks << task @branch_tasks[task.branch_name] = task @ln_tasks[task.ln] = task @top_tasks << task if task.level == 1 end end end fh.close # check and set dependencies self.tasks.each do |task| task.dependencie_names.each do |branch| d_task = @branch_tasks[branch] raise "task #{task.branch_name} (#{task.file}:#{task.ln}) has dependency #{branch} not found on the file" unless d_task task.dependencies << d_task end end self end |
#rewrite!(task_hash) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/dev_flow/roadmap.rb', line 97 def rewrite! task_hash # task_hash: {task_line_as_integer => progress_as_integer} task_hash.each do |ln, progress| raise "invalid line number #{ln}" unless ln.to_s =~ /^\d+$/ and ln > 0 raise "invalid progress #{progress}" unless progress.to_s =~ /^\d+$/ and progress > 0 and progress <= 100 end file = self.file tmp_file = self.file + ".tmp" # backup the file to tmp_file FileUtils.mv file, tmp_file tfh = File.open(tmp_file, "r:utf-8") wfh = File.open(file, "w:utf-8") tfh.each do |line| if task_hash[$.] progress = task_hash[$.] task = @ln_tasks[$.] if progress == 100 com_date = DateTime.now.strftime("%Y/%m/%d") com_date = DateTime.now.strftime("%m/%d") if DateTime.now.year == @config["year"] progress = com_date end new_line = line if /(?<resource_>\@[a-z\@\;]+)(\:[PD\d\/]+)?/ =~ line new_line.gsub!(/(?<resource_>\@[a-z\@\;]+)(\:[PD\d\/]+)?/, resource_ + ":" + progress.to_s) elsif /(?<dep_>\-\>.+)$/ =~ line new_line.gsub!(/\s*\-\>.+$/, '@' + self.config["leader"] + ":" + progress.to_s + " " + dep_) else new_line += '@' + self.config["leader"] + ":" + progress.to_s end wfh.puts new_line else wfh.puts line end end tfh.close wfh.close FileUtils.rm tmp_file end |
#team_member_names ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/dev_flow/roadmap.rb', line 25 def team_member_names mary = @config["team"] || Array.new %w[leader moderator supervisor].each do |role| if @config[role] mary << @config[role] unless mary.include? @config[role] end end mary end |
#title ⇒ Object
21 22 23 |
# File 'lib/dev_flow/roadmap.rb', line 21 def title @config["title"] end |