Class: Saga::Planning
- Inherits:
-
Object
- Object
- Saga::Planning
- Defined in:
- lib/saga/planning.rb
Constant Summary collapse
- BLANK_ITERATION =
{:story_count => 0, :estimate_total_in_hours => 0}
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(document) ⇒ Planning
constructor
A new instance of Planning.
- #iterations ⇒ Object
- #to_s ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(document) ⇒ Planning
Returns a new instance of Planning.
5 6 7 |
# File 'lib/saga/planning.rb', line 5 def initialize(document) @document = document end |
Class Method Details
.estimate_to_hours(estimate) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/saga/planning.rb', line 44 def self.estimate_to_hours(estimate) case estimate[1] when :days estimate[0] * 8 when :weeks estimate[0] * 40 else estimate[0] end end |
.format_properties(iteration, properties) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/saga/planning.rb', line 55 def self.format_properties(iteration, properties) if iteration label = (iteration == -1) ? "Unplanned" : "Iteration #{iteration}" else label = 'Total' end story_column = (properties[:story_count] == 1) ? "#{properties[:story_count]} story" : "#{properties[:story_count]} stories" "#{label.ljust(14)}: #{properties[:estimate_total_in_hours]} (#{story_column})" end |
Instance Method Details
#iterations ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/saga/planning.rb', line 9 def iterations @document.stories.values.flatten.inject({}) do |properties, story| if 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 properties end end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/saga/planning.rb', line 30 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 formatted_totals = self.class.format_properties(false, total) parts << '-'*formatted_totals.length parts << formatted_totals parts.join("\n") end end |
#total ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/saga/planning.rb', line 21 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 |