Class: Saga::Planning

Inherits:
Object
  • Object
show all
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

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



57
58
59
60
61
62
63
64
65
66
# File 'lib/saga/planning.rb', line 57

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



68
69
70
71
72
73
74
75
76
# File 'lib/saga/planning.rb', line 68

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

.format_unestimated(unestimated) ⇒ Object



78
79
80
# File 'lib/saga/planning.rb', line 78

def self.format_unestimated(unestimated)
  "Unestimated   : #{unestimated > 1 ? "#{unestimated} stories" : 'one story' }"
end

Instance Method Details

#iterationsObject



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_sObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/saga/planning.rb', line 40

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
    parts << self.class.format_unestimated(unestimated) if unestimated > 0
    parts.join("\n")
  end
end

#totalObject



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

#unestimatedObject



30
31
32
33
34
35
36
37
38
# File 'lib/saga/planning.rb', line 30

def unestimated
  unestimated = 0
  @document.stories.values.each do |stories|
    stories.each do |story|
      unestimated += 1 unless story[:estimate]
    end
  end
  unestimated
end