class Saga::Planning
Constants
- BLANK_ITERATION
- FIRST_COLUMN_WIDTH
Public Class Methods
estimate_to_hours(estimate)
click to toggle source
# File lib/saga/planning.rb, line 87 def self.estimate_to_hours(estimate) case estimate[1] when :days estimate[0] * 8 when :weeks estimate[0] * 40 when :range 0 else estimate[0] end end
format_properties(iteration, properties)
click to toggle source
# File lib/saga/planning.rb, line 100 def self.format_properties(iteration, properties) label = if iteration iteration == -1 ? 'Unplanned' : "Iteration #{iteration}" else 'Total' end story_column = format_stories_count(properties[:story_count]) "#{label.ljust(FIRST_COLUMN_WIDTH)}: #{properties[:estimate_total_in_hours]} (#{story_column})" end
format_range_estimated(range_estimated)
click to toggle source
# File lib/saga/planning.rb, line 114 def self.format_range_estimated(range_estimated) "Range-estimate: #{format_stories_count(range_estimated)}" end
format_statusses(statusses)
click to toggle source
# File lib/saga/planning.rb, line 122 def self.format_statusses(statusses) parts = [] statusses.each do |status, hours| parts << "#{status.capitalize.ljust(FIRST_COLUMN_WIDTH)}: #{hours}" end parts.join("\n") end
format_stories_count(count)
click to toggle source
# File lib/saga/planning.rb, line 118 def self.format_stories_count(count) count > 1 ? "#{count} stories" : 'one story' end
format_unestimated(unestimated)
click to toggle source
# File lib/saga/planning.rb, line 110 def self.format_unestimated(unestimated) "Unestimated : #{format_stories_count(unestimated)}" end
new(document)
click to toggle source
# File lib/saga/planning.rb, line 5 def initialize(document) unless document raise ArgumentError, 'Please supply a document for planning.' end @document = document end
Public Instance Methods
iterations()
click to toggle source
# File lib/saga/planning.rb, line 13 def iterations @document.stories_as_flat_list.each_with_object({}) do |story, properties| next unless story[:estimate] iteration = story[:iteration] || -1 properties[iteration] ||= BLANK_ITERATION.dup properties[iteration][:story_count] += 1 properties[iteration][:estimate_total_in_hours] += self.class.estimate_to_hours(story[:estimate]) end end
range_estimated()
click to toggle source
# File lib/saga/planning.rb, line 41 def range_estimated range_estimated = 0 @document.stories_as_flat_list.each do |story| if story[:estimate] && story[:estimate][1] == :range range_estimated += 1 end end range_estimated end
statusses()
click to toggle source
# File lib/saga/planning.rb, line 51 def statusses statusses = {} @document.stories_as_flat_list.each do |story| if story[:estimate] && story[:status] statusses[story[:status]] ||= 0 statusses[story[:status]] += self.class.estimate_to_hours(story[:estimate]) end end statusses end
to_s()
click to toggle source
# File lib/saga/planning.rb, line 62 def to_s if @document.empty? 'There are no stories yet.' else parts = iterations.keys.sort.map do |iteration| self.class.format_properties(iteration, iterations[iteration]) end unless parts.empty? formatted_totals = self.class.format_properties(false, total) parts << '-' * formatted_totals.length parts << formatted_totals end if (unestimated > 0) || !statusses.empty? parts << '' parts << self.class.format_unestimated(unestimated) if unestimated > 0 parts << self.class.format_range_estimated(range_estimated) if range_estimated > 0 parts << self.class.format_statusses(statusses) unless statusses.empty? end parts.shift if parts[0] == '' parts.join("\n") end end
total()
click to toggle source
# File lib/saga/planning.rb, line 24 def total total = BLANK_ITERATION.dup iterations.each do |_iteration, properties| total[:story_count] += properties[:story_count] total[:estimate_total_in_hours] += properties[:estimate_total_in_hours] end total end
unestimated()
click to toggle source
# File lib/saga/planning.rb, line 33 def unestimated unestimated = 0 @document.stories_as_flat_list.each do |story| unestimated += 1 unless story[:estimate] end unestimated end