-
Notifications
You must be signed in to change notification settings - Fork 15
/
sprint.rb
81 lines (63 loc) · 1.79 KB
/
sprint.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require_relative 'sprint_boundary_iterator'
class Sprint
def self.prompt_for_sprint(count)
sprints = recent_sprints(count).reverse
default_index = Date.today == sprints.first.range.begin ? 1 : 0
sprints[prompt_user(sprints, default_index)]
end
private_class_method def self.prompt_user(sprints, default_index)
default_index += 1
sprints.each_with_index { |s, i| puts "#{i + 1} : #{s.title}" }
puts "#{sprints.size + 1} : Exit"
print "\nChoose Sprint: [Default: #{default_index}] "
answer = gets.chomp.to_i
(answer.zero? ? default_index : answer) - 1
end
def self.recent_sprints(count)
sprints(as_of: nil).slice_after { |s| s.date >= Date.today }.first.last(count)
end
def self.last_completed
Sprint.recent_sprints(2).first
end
def self.create_by_sprint_number(sprint_number)
SprintBoundaryIterator.new.each do |number, range|
return new(number, range) if number == sprint_number
end
nil
end
def self.sprints(as_of: Date.today)
as_of ||= SprintBoundaryIterator.start_range.end
SprintBoundaryIterator.new.collect do |number, range|
new(number, range) if range.end >= as_of
end
end
attr_reader :number, :range
def initialize(number, range)
@number, @range = number, range
end
def before_range?(timestamp)
timestamp.to_date < range.begin
end
def after_range?(timestamp)
timestamp.to_date > range.end
end
def in_range?(timestamp)
return false if timestamp.nil?
range.include?(timestamp.to_date)
end
def began_iso8601
range.first.iso8601
end
def ended_iso8601
range.end.iso8601
end
def range_iso8601
"#{began_iso8601}..#{ended_iso8601}"
end
def date
range.end
end
def title
"Sprint #{number} Ending #{date.strftime("%b %-d, %Y")}"
end
end