Class: PivotalReport

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

Constant Summary collapse

POST_EST =
'epost'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PivotalReport

Returns a new instance of PivotalReport.



11
12
13
14
# File 'lib/pivotal_report.rb', line 11

def initialize(options)
  PivotalTracker::Client.token = options[:token]
  @project = PivotalTracker::Project.find(options[:project_id])
end

Instance Method Details

#reportObject



18
19
20
21
22
23
24
25
26
# File 'lib/pivotal_report.rb', line 18

def report
  show_discussion_items
  separator
  show_story_bullets
  separator
  show_ppu_table
  separator
  show_stories_in_progress
end

#separatorObject



33
34
35
# File 'lib/pivotal_report.rb', line 33

def separator
  puts "\n-----\n\n"
end

#show_accounting_breakdownObject



28
29
30
31
# File 'lib/pivotal_report.rb', line 28

def show_accounting_breakdown
  # TODO
  raise 'Unimplemented!'
end

#show_discussion_itemsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pivotal_report.rb', line 37

def show_discussion_items
  puts "Discussion Items"
  puts ""
  estimates = stories.sort{|a,b| a.owned_by.to_s <=> b.owned_by.to_s }.map(&:labels).map{|e| e.to_s.split(/,/) }.flatten.map(&:strip).compact.uniq.select{|l| l =~ /^(#{POST_EST}|e\d)$/ }.sort
  estimates.each do |est|
    set = stories_with_label(est)
    set.each do |story|
      puts "(\e[31m#{story.estimate}\e[0m: \e[32m#{est}\e[0m) #{story.name.strip} (\e[33m#{story.initials}\e[0m) [\e[34m#{story.labels}\e[0m]"
    end
  end
end

#show_ppu_tableObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
# File 'lib/pivotal_report.rb', line 68

def show_ppu_table
  puts "PPU Table"

  categories = stories.map(&:labels).map{|e| e.to_s.split(/,/) }.flatten.map(&:strip).compact.uniq.reject{|l| l =~ /^(#{POST_EST}|e\d)$/ }.sort
  people = stories.map(&:owned_by).uniq.compact.sort.map{|p| [p, p.split(/ /).first]}
  c_width = (['Total'] + categories).map(&:length).max

  sseen = []

  o = []
  o << "".ljust(c_width)
  o << " | "
  people.each {|p| o << p[1]; o << " | " }
  o << " Total || Feature | Bug | Chore |"
  puts o.join

  categories.each do |cat|
    o = []
    o << cat.ljust(c_width)
    o << " | "
    people.each do |person, short|
      o << stories_for_user(person, stories_with_label(cat)).map(&:estimate).inject(0){|s,e| s + e }.to_s.rjust(short.length)
      o << " | "
    end
    set = stories_with_label(cat)
    sseen += set
    o << set.map(&:estimate).inject(0){|s,e| s + e.to_i }.to_s.rjust('Total '.length)
    o << " || "
    %w{feature bug chore}.each do |type|
      o << stories_with_label(cat, stories_for_type(type)).map(&:estimate).inject(0){|s,e| s + e.to_i }.to_s.rjust(type.length)
      o << " | "
    end
    puts o.join
  end

  o = []
  o << "-" * c_width
  o << "-+-"
  people.each do |person, short|
    o << "-" * short.length
    o << "-+-"
  end
  o << "-------++---------+-----+-------+"
  puts o.join

  o = []
  o << "Total".ljust(c_width)
  o << " | "
  people.each do |person, short|
    o << stories_for_user(person).map(&:estimate).inject(0){|s,e| s + e }.to_s.rjust(short.length)
    o << " | "
  end
  o << stories.map(&:estimate).inject(0){|s,e| s + e.to_i }.to_s.rjust('Total '.length)
  o << " || "
  %w{feature bug chore}.each do |type|
    o << stories_for_type(type).map(&:estimate).inject(0){|s,e| s + e.to_i }.to_s.rjust(type.length)
    o << " | "
  end
  puts o.join

  missing = stories - sseen
  if missing.any?
    puts "Missing:"
    puts missing.map(&:name).join("\n")
  end

end

#show_stories_in_progressObject



136
137
138
139
140
141
# File 'lib/pivotal_report.rb', line 136

def show_stories_in_progress
  in_progress = @project.stories.all(:state => ['started', 'delivered'])
  points_in_progress = in_progress.map(&:estimate).inject(0){|s,e| s+e}

  puts "In Progress: #{points_in_progress} points"
end

#show_story_bulletsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pivotal_report.rb', line 49

def show_story_bullets
  puts "Story Bullets"
  puts ""
  lis = nil
  stories.sort{|a,b| a.owned_by.to_s <=> b.owned_by.to_s }.each do |story|
    if story.initials != lis
      lis = story.initials
      puts "#{story.initials}:"
    end
    letter = story.story_type.to_s[0]
    color = case letter
            when 'f' then 33
            when 'b' then 31
            when 'c' then 32
            end
    puts "\e[#{color}m#{letter}#{story.estimate} \e[0m#{story.name.strip} [\e[34m#{story.labels}\e[0m]"
  end
end