Class: SimpleCov::Formatter::AIFormatter::MarkdownBuilder::DeficitGrouper
- Inherits:
-
Object
- Object
- SimpleCov::Formatter::AIFormatter::MarkdownBuilder::DeficitGrouper
- Extended by:
- T::Sig
- Defined in:
- lib/simplecov-ai/markdown_builder/deficit_grouper.rb
Overview
Groups missed lines, branches and methods into DeficitGroup objects based on AST semantic boundaries. Every deficit inside the file lands on its innermost enclosing node (the resolver's root scope at worst); only a deficit no node spans — reported by SimpleCov for a file that vanished or shrank after coverage was recorded — falls back to a positional label.
Constant Summary collapse
- FALLBACK_LINE_NAME =
Positional label for a single-line deficit no resolved node spans; a missed line and a single-line branch at the same line share it.
T.let('Line %d', String)
- FALLBACK_RANGE_NAME =
Positional label for a multi-line deficit no resolved node spans.
T.let('Lines %d-%d', String)
Class Method Summary collapse
Instance Method Summary collapse
- #group_missed_branches(file) ⇒ Object
- #group_missed_lines(file) ⇒ Object
- #group_missed_methods(method_deficits) ⇒ Object
-
#initialize(nodes) ⇒ DeficitGrouper
constructor
A new instance of DeficitGrouper.
- #sort_deficits ⇒ Object
Constructor Details
#initialize(nodes) ⇒ DeficitGrouper
Returns a new instance of DeficitGrouper.
23 24 25 26 27 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 23 def initialize(nodes) @nodes = nodes @node_deficits = T.let({}, T::Hash[String, DeficitGroup]) @sort_keys = T.let({}, T::Hash[String, [Integer, Integer]]) end |
Class Method Details
.build(file, nodes, method_deficits) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 39 def self.build(file, nodes, method_deficits) grouper = new(nodes) grouper.group_missed_lines(file) grouper.group_missed_branches(file) grouper.group_missed_methods(method_deficits) grouper.sort_deficits end |
.raw_group(file, method_deficits) ⇒ Object
54 55 56 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 54 def self.raw_group(file, method_deficits) DeficitGroup.new(lines: file.missed_lines, branches: file.missed_branches, method_deficits: method_deficits) end |
Instance Method Details
#group_missed_branches(file) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 76 def group_missed_branches(file) file.missed_branches.each do |branch| matched_node = innermost_node_for(branch.start_line, branch.end_line) group_for(matched_node, branch.start_line, branch.end_line).branches << branch end end |
#group_missed_lines(file) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 68 def group_missed_lines(file) file.missed_lines.each do |line| line_number = line.line_number group_for(innermost_node_for(line_number, line_number), line_number, line_number).lines << line end end |
#group_missed_methods(method_deficits) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 84 def group_missed_methods(method_deficits) method_deficits.each do |method_deficit| start_line = method_deficit.start_line end_line = method_deficit.end_line deficit_group = group_for(innermost_node_for(start_line, end_line), start_line, end_line) deficit_group.method_deficits << method_deficit end end |
#sort_deficits ⇒ Object
62 63 64 65 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 62 def sort_deficits sorted = @node_deficits.sort_by { |group_key, _group| @sort_keys.fetch(group_key) } T.let(sorted.to_h, T::Hash[String, DeficitGroup]) end |