Class: Agentilda::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/agentilda/reporter.rb

Overview

/spec-status — every plan, its state in icon and words, and its pull requests as clickable links.

#render returns a string and prints nothing. Whoever calls it decides where it goes, which keeps the table pipeable.

Constant Summary collapse

HEADINGS =

Columns, so the header and the rows cannot drift apart.

["Plan", "", "Status", "Feature", "Pull Requests"].freeze
ORDINAL_WIDTH =

Cells given to the plan number: "018.01" with room to grow.

7
EMOJI_WIDTH =

Cells given to a status icon. Emoji vary in both character count and display width, so the cell is padded to this by UI.fit rather than trusted to be any particular size — see the note there.

2
STATE_WIDTH =

Cells given to a pull request's state, so the URLs line up beneath each other whichever states the tree happens to contain.

PullRequests::STATES.map { |_, label| UI.display_width(label) }.max

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree:) ⇒ Reporter

Returns a new instance of Reporter.

Parameters:



26
27
28
# File 'lib/agentilda/reporter.rb', line 26

def initialize(tree:)
  @tree = tree
end

Instance Attribute Details

#treeAgentilda::Tree (readonly)

Returns:



31
32
33
# File 'lib/agentilda/reporter.rb', line 31

def tree
  @tree
end

Instance Method Details

#inconsistentArray<Agentilda::Subject>

Plans whose folder name their contents do not justify.

Returns:



48
# File 'lib/agentilda/reporter.rb', line 48

def inconsistent = tree.subjects.reject(&:consistent?)

#renderString

Returns the whole table, newline-terminated.

Returns:

  • (String)

    the whole table, newline-terminated



34
35
36
37
38
# File 'lib/agentilda/reporter.rb', line 34

def render
  return "No plans found in #{tree.dir}\n" if tree.subjects.empty?

  [header, *tree.subjects.flat_map { |s| rows_for(s) }, "", footer].join("\n") + "\n"
end

#totalsHash{Symbol => Integer}

Returns how many plans sit in each state.

Returns:

  • (Hash{Symbol => Integer})

    how many plans sit in each state



41
42
43
# File 'lib/agentilda/reporter.rb', line 41

def totals
  tree.subjects.each_with_object(Hash.new(0)) { |s, h| h[s.status.key] += 1 }
end