Class: TPS::CliReporter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ CliReporter

Returns a new instance of CliReporter.



5
6
7
# File 'lib/tps/cli_reporter.rb', line 5

def initialize(task)
  @task = task
end

Instance Attribute Details

#taskObject (readonly)

Returns the value of attribute task.



3
4
5
# File 'lib/tps/cli_reporter.rb', line 3

def task
  @task
end

Instance Method Details

#colorObject



47
48
49
50
51
52
53
54
55
# File 'lib/tps/cli_reporter.rb', line 47

def color
  if task.done?
    32
  elsif task.in_progress?
    34
  else
    30
  end
end

#pointsObject



39
40
41
42
43
44
45
# File 'lib/tps/cli_reporter.rb', line 39

def points
  [
    "%3i" % [ task.points_done ],
    c("/", 30),
    c("%-2i" % [ task.points ], 32)
  ].join ''
end


9
10
11
# File 'lib/tps/cli_reporter.rb', line 9

def print
  puts report
end

#progressObject



69
70
71
72
73
74
75
76
77
# File 'lib/tps/cli_reporter.rb', line 69

def progress
  max = 12
  len = (task.percent * max).to_i

  prog = ("%-#{max}s" % ["="*len])
  prog = c(""*len, color) + c(""*(max-len), 30)

  prog
end

#reportObject



13
14
15
16
17
18
19
20
# File 'lib/tps/cli_reporter.rb', line 13

def report
  re = ""
  task.walk do |t, recurse|
    re += CliReporter.new(t).report_task
    recurse.call  if recurse
  end
  re
end

#report_taskObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tps/cli_reporter.rb', line 22

def report_task
  indent = ' ' * (4 * task.level)

  # Columns
  c1 = "%s %s %s" % [ indent, status, task.name ]
  c2 = if task.feature? || task.milestone?
         "%6s %s" % [ points, progress ]
      else
        ' '*19
      end

  pref = c(""*80, 30)+"\n"  if task.feature?

  # Put together
  "#{pref}" + "%-88s%s\n" % [ c1, c2 ]
end

#statusObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tps/cli_reporter.rb', line 57

def status
  l = c("", 30)
  r = c(" ", 30)
  if task.done?
     l + c('', color) + r
  elsif task.in_progress?
    l + c('', color) + r
  else
    l + c(' ', color) + r
  end
end