class TPS::BarFormatter
Presenter for tasks to format things into bars.
Attributes
task[R]
Public Class Methods
new(task)
click to toggle source
# File lib/tps/bar_formatter.rb, line 6 def initialize(task) @task = task end
Public Instance Methods
all_sprints()
click to toggle source
# File lib/tps/bar_formatter.rb, line 15 def all_sprints @all_sprints ||= @task.list.sprints.values end
index_segments()
click to toggle source
Returns segments of the indices of sprints.
# File lib/tps/bar_formatter.rb, line 20 def index_segments to_segments(sprints.map(&:index)) end
label()
click to toggle source
# File lib/tps/bar_formatter.rb, line 60 def label sprints.map(&:id).join(" ") end
segments()
click to toggle source
Returns segments. Lines are in the format:
|type, (size, sprints)|
# File lib/tps/bar_formatter.rb, line 32 def segments re = Array.new last_max = -1 segs = index_segments segs.each_with_index do |range, i| sprints = range.to_a.map { |i| all_sprints[i] } span = range.max - range.min + 1 w = range.min-last_max-1 line_length = segment_width * w + inner_pad marker_length = segment_width * span - inner_pad re << [ :line, [line_length, sprints] ] re << [ :marker, [marker_length, sprints] ] last_max = range.max end # Last line butal = all_sprints.length - sprints.last.index - 1 re << [ :line, segment_width * butal + inner_pad ] re end
sprints()
click to toggle source
Array of sprints.
# File lib/tps/bar_formatter.rb, line 11 def sprints @sprints ||= task.sprints end
visible?()
click to toggle source
# File lib/tps/bar_formatter.rb, line 24 def visible? sprints.any? end
Private Instance Methods
inner_pad()
click to toggle source
# File lib/tps/bar_formatter.rb, line 67 def inner_pad() 12; end
segment_width()
click to toggle source
# File lib/tps/bar_formatter.rb, line 66 def segment_width() 35; end
to_segments(indexes)
click to toggle source
Connects an array of numeric indices. Returns an array of ranges.
to_segments([2,3,4,5,6,14,15]) #=> [ (2..6), (14..15) ]
# File lib/tps/bar_formatter.rb, line 74 def to_segments(indexes) segments = Array.new ([-1] + indexes).each_cons(2) do |prev, i| if prev == -1 segments << (i..i) prev = i-1 end if prev.next == i segments[segments.length-1] = ((segments[segments.length-1].min)..i) else segments << (i..i) end end segments end