Class: TPS::BarFormatter
- Inherits:
-
Object
- Object
- TPS::BarFormatter
- Defined in:
- lib/tps/bar_formatter.rb
Overview
Presenter for tasks to format things into bars.
Instance Attribute Summary collapse
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
- #all_sprints ⇒ Object
-
#index_segments ⇒ Object
Returns segments of the indices of sprints.
-
#initialize(task) ⇒ BarFormatter
constructor
A new instance of BarFormatter.
- #label ⇒ Object
-
#segments ⇒ Object
Returns segments.
-
#sprints ⇒ Object
Array of sprints.
- #visible? ⇒ Boolean
Constructor Details
#initialize(task) ⇒ BarFormatter
Returns a new instance of BarFormatter.
6 7 8 |
# File 'lib/tps/bar_formatter.rb', line 6 def initialize(task) @task = task end |
Instance Attribute Details
#task ⇒ Object (readonly)
Returns the value of attribute task.
4 5 6 |
# File 'lib/tps/bar_formatter.rb', line 4 def task @task end |
Instance Method Details
#all_sprints ⇒ Object
15 16 17 |
# File 'lib/tps/bar_formatter.rb', line 15 def all_sprints @all_sprints ||= @task.list.sprints.values end |
#index_segments ⇒ Object
Returns segments of the indices of sprints.
20 21 22 |
# File 'lib/tps/bar_formatter.rb', line 20 def index_segments to_segments(sprints.map(&:index)) end |
#label ⇒ Object
60 61 62 |
# File 'lib/tps/bar_formatter.rb', line 60 def label sprints.map(&:id).join(" ") end |
#segments ⇒ Object
Returns segments. Lines are in the format:
|type, (size, sprints)|
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 |
# 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 ⇒ Object
Array of sprints.
11 12 13 |
# File 'lib/tps/bar_formatter.rb', line 11 def sprints @sprints ||= task.sprints end |
#visible? ⇒ Boolean
24 25 26 |
# File 'lib/tps/bar_formatter.rb', line 24 def visible? sprints.any? end |