module Pivotal::Tracker::Mapper

Mapper of outer resource This version only for Pivotal Tracker @author Tsuyoshi Ushio

Public Class Methods

append_features(base) click to toggle source
Calls superclass method
# File lib/pivotal/tracker/mapper.rb, line 11
def self.append_features(base)
  begin
    config = YAML.load_file('.speedchart')
  rescue
    puts "Please create config file '.speedchart'"
    exit -1
  end

  begin
    PivotalTracker::Client.token = config['token']
    @@project = PivotalTracker::Project.find(config['project_id'])
  rescue RestClient::Unauthorized
    puts "Wrong token. please check out .speedchart"
    exit -1
  rescue RestClient::ResourceNotFound
    puts "Wrong project_id. please check out .speedchart"
    exit -1
  end

    @@project_started_at = config['started_at']

    unless @@project_started_at.class == Date
     puts "Wrong started_at. please check out .speedchart"
     exit -1
    end

  super
end
current_stories() click to toggle source

Returns stories on the BackLog @return [Array<PivotalTracker::Story>] stories on the backlog

# File lib/pivotal/tracker/mapper.rb, line 46
def current_stories
  # type = feature and not unscheduled
  @@project.stories.all.select{|x| (x.story_type == "feature") && (x.current_state != "unscheduled")}
end
project_started_at() click to toggle source
# File lib/pivotal/tracker/mapper.rb, line 40
def project_started_at
  @@project_started_at
end
summrize_stories(from_date, to_date = Date.today) click to toggle source

Returns All Story Num, Accepted Num and Todo Num @param from_date [Date] the first date of speed chart @param to_date [Date] the last date of speed chart @return [Array<Date, Integer, Integer,Integer>] [Date, Total, Accepted, Todo]

# File lib/pivotal/tracker/mapper.rb, line 88
def summrize_stories(from_date, to_date = Date.today)
  stories = current_stories
  story_summaries = Array.new
  (from_date .. to_date).each{|current_date|
    if (current_date <= Date.today) then
      story_summaries << [current_date , aggrigate_story_size_by_date(current_date, stories)].flatten
    else
      story_summaries << [current_date , [nil, nil, nil]]
    end
  }
  story_summaries
end

Public Instance Methods

accepted_stories(date, stories) click to toggle source

Returns all stories accepted and created before the date @param date [Date] the date @param stories [PivotalTracker::Story] Stories @return [Array<PivotalTracker::Story>] stories accepted and created before the date

# File lib/pivotal/tracker/mapper.rb, line 70
def accepted_stories(date, stories)
  stories.select{|story| (!story.accepted_at.nil? && story.accepted_at.to_date <= date)}
end
aggrigate_story_size_by_date(date, stories) click to toggle source

Returns the report of the story sizes. @param date [Date] the date @param stories [PivotalTracker::Story] Stories @return [Array<Integer,Integer,Integer,Integer>] [Total, Accepted, Todo]

# File lib/pivotal/tracker/mapper.rb, line 78
def aggrigate_story_size_by_date(date, stories)
  total_size = total_stories(date, stories).size
  accepted_size =  accepted_stories(date, stories).size
  [total_size, accepted_size, total_size - accepted_size]
end
find_by_state_stories(state) click to toggle source

Return stories match the state @param [String] state of story (unstarted/finished/delivered/accepted) @return [Array<PivotalTracker::Story>] stories on the backlog selected by state

# File lib/pivotal/tracker/mapper.rb, line 54
def find_by_state_stories(state)
  current_stories.select{|x| x.current_state == state}
end
total_stories(date, stories) click to toggle source

Returns all stories created before the date @param date [Date] the date @param stories [PivotalTracker::Story] Stories @return [Array<PivotalTracker::Story>] stories created befor the date

# File lib/pivotal/tracker/mapper.rb, line 62
def total_stories(date, stories)
  stories.select{|story| story.created_at.to_date <= date}
end

Private Instance Methods

current_stories() click to toggle source

Returns stories on the BackLog @return [Array<PivotalTracker::Story>] stories on the backlog

# File lib/pivotal/tracker/mapper.rb, line 46
def current_stories
  # type = feature and not unscheduled
  @@project.stories.all.select{|x| (x.story_type == "feature") && (x.current_state != "unscheduled")}
end
project_started_at() click to toggle source
# File lib/pivotal/tracker/mapper.rb, line 40
def project_started_at
  @@project_started_at
end
summrize_stories(from_date, to_date = Date.today) click to toggle source

Returns All Story Num, Accepted Num and Todo Num @param from_date [Date] the first date of speed chart @param to_date [Date] the last date of speed chart @return [Array<Date, Integer, Integer,Integer>] [Date, Total, Accepted, Todo]

# File lib/pivotal/tracker/mapper.rb, line 88
def summrize_stories(from_date, to_date = Date.today)
  stories = current_stories
  story_summaries = Array.new
  (from_date .. to_date).each{|current_date|
    if (current_date <= Date.today) then
      story_summaries << [current_date , aggrigate_story_size_by_date(current_date, stories)].flatten
    else
      story_summaries << [current_date , [nil, nil, nil]]
    end
  }
  story_summaries
end