Sha256: 67f39aa16e7944673f58d76ead382b27592e2fd7f37d0a7fc7cdf931e0aca772

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

module DevFlow

  class Task
    def as_title header = ' '
      name = self.display_name
      name = self.display_name.bold if self.is_workable?
      name = self.display_name.blue if self.progress > 0
      name = self.display_name.green if self.is_completed?
      name = self.display_name.magenta if self.is_urgent?
      name = self.display_name.red if self.is_delayed?

      if self.progress > 0 and self.progress < 100
        on_branch = sprintf "(=> %s, %02d%%)", self.branch_name.bold, self.progress
      end

      title = sprintf("%s[%s]%s (%s-%s) %s", '  '*(self.level-1), header, name, DateName.zh(self.start_date).bold, DateName.zh(self.end_date).bold, on_branch)
    end

    ## a task is completable if all children complated
    def is_completable?
      return false if self.is_completed? 
      self.children.each do |child|
        return false unless child.is_completed?
      end
      true
    end

    ## a task is workable (can be started) if all children
    # task and dependent task are completed
    def is_workable?
      # trivial: if already completed, do not start again
      return false if self.is_completed?
      return false if self.is_pending or self.is_deleted

      self.dependencies.each do |t|
        return false unless t.is_completed?
      end

      self.children.each do |t|
        return false unless t.is_completed?
      end
      true
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dev_flow-0.2.3 lib/dev_flow/task_console.rb
dev_flow-0.2.2 lib/dev_flow/task_console.rb
dev_flow-0.2.1 lib/dev_flow/task_console.rb
dev_flow-0.2.0 lib/dev_flow/task_console.rb