Class: Central::Support::Iteration

Inherits:
Array
  • Object
show all
Defined in:
lib/central/support/iteration.rb

Overview

mimics the iteration.js counterpart

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, iteration_number, maximum_points = nil) ⇒ Iteration

Returns a new instance of Iteration.



7
8
9
10
11
12
13
# File 'lib/central/support/iteration.rb', line 7

def initialize(service, iteration_number, maximum_points = nil)
  @service        = service
  @number         = iteration_number
  @maximum_points = maximum_points
  @is_full        = false
  super([])
end

Instance Attribute Details

#maximum_pointsObject (readonly)

Returns the value of attribute maximum_points.



5
6
7
# File 'lib/central/support/iteration.rb', line 5

def maximum_points
  @maximum_points
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/central/support/iteration.rb', line 5

def number
  @number
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



5
6
7
# File 'lib/central/support/iteration.rb', line 5

def start_date
  @start_date
end

Instance Method Details

#available_pointsObject



19
20
21
# File 'lib/central/support/iteration.rb', line 19

def available_points
  maximum_points - points
end

#can_take_story?(story) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
# File 'lib/central/support/iteration.rb', line 23

def can_take_story?(story)
  return true if %w(started finished delivered accepted rejected).include? story.state
  return false if @is_full
  return true if points == 0
  return true if story.story_type != 'feature'

  @is_full = (story.estimate || 0) > available_points
  !@is_full
end

#detailsObject



42
43
44
45
46
47
48
# File 'lib/central/support/iteration.rb', line 42

def details
  {
    points: self.reduce(0) { |total, story| total + (story.estimate || 0) },
    count: self.size,
    non_estimable: self.select { |story| !Story::ESTIMABLE_TYPES.include?(story.story_type) }.size
  }
end

#overflows_byObject



33
34
35
36
# File 'lib/central/support/iteration.rb', line 33

def overflows_by
  difference = points - maximum_points
  difference < 0 ? 0 : difference
end

#pointsObject



15
16
17
# File 'lib/central/support/iteration.rb', line 15

def points
  self.reduce(0) { |total, story| total + ( story.estimate || 0 ) }
end