class PivotalReport

Constants

POST_EST

Public Class Methods

new(options) click to toggle source
# File lib/pivotal_report.rb, line 11
def initialize(options)
  PivotalTracker::Client.token = options[:token]
  @project = PivotalTracker::Project.find(options[:project_id])
end

Public Instance Methods

report() click to toggle source
# 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
separator() click to toggle source
# File lib/pivotal_report.rb, line 33
def separator
  puts "\n-----\n\n"
end
show_accounting_breakdown() click to toggle source
# File lib/pivotal_report.rb, line 28
def show_accounting_breakdown
  # TODO
  raise 'Unimplemented!'
end
show_discussion_items() click to toggle source
# 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_table() click to toggle source
# 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_progress() click to toggle source
# 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_bullets() click to toggle source
# 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

Private Instance Methods

iteration() click to toggle source
# File lib/pivotal_report.rb, line 146
def iteration
  @iteration ||= PivotalTracker::Iteration.done(@project, :offset => '-1').first
end
stories() click to toggle source
# File lib/pivotal_report.rb, line 150
def stories
  @stories ||= iteration.stories
end
stories_for_type(type, set=nil) click to toggle source
# File lib/pivotal_report.rb, line 164
def stories_for_type(type, set=nil)
  set ||= stories
  set.select{|s| s.story_type == type }
end
stories_for_user(user, set=nil) click to toggle source
# File lib/pivotal_report.rb, line 159
def stories_for_user(user, set=nil)
  set ||= stories
  set.select{|s| s.owned_by.to_s == user }
end
stories_with_label(label, set=nil) click to toggle source
# File lib/pivotal_report.rb, line 154
def stories_with_label(label, set=nil)
  set ||= stories
  set.select{|s| s.labels.to_s =~ /(^|,)#{label}($|,)/ }
end