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 and branches into DeficitGroup objects based on AST semantic boundaries.
Instance Attribute Summary collapse
-
#node_deficits ⇒ Object
readonly
Returns the value of attribute node_deficits.
Class Method Summary collapse
Instance Method Summary collapse
- #add_missed_branch(branch) ⇒ Object
- #add_missed_line(line) ⇒ Object
- #group_missed_branches(file) ⇒ Object
- #group_missed_lines(file) ⇒ Object
-
#initialize(nodes) ⇒ DeficitGrouper
constructor
A new instance of DeficitGrouper.
- #sort_deficits ⇒ Object
Constructor Details
#initialize(nodes) ⇒ DeficitGrouper
Returns a new instance of DeficitGrouper.
16 17 18 19 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 16 def initialize(nodes) @nodes = nodes @node_deficits = T.let({}, T::Hash[String, DeficitGroup]) end |
Instance Attribute Details
#node_deficits ⇒ Object (readonly)
Returns the value of attribute node_deficits.
13 14 15 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 13 def node_deficits @node_deficits end |
Class Method Details
.build(file, nodes) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 25 def self.build(file, nodes) grouper = new(nodes) grouper.group_missed_lines(file) grouper.group_missed_branches(file) grouper.sort_deficits end |
Instance Method Details
#add_missed_branch(branch) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 72 def add_missed_branch(branch) start_line = branch.start_line end_line = branch.end_line node = @nodes.reverse.find { |n| start_line >= n.start_line && end_line <= n.end_line } node_name = node ? node.name : "Lines #{start_line}-#{end_line}" @node_deficits[node_name] ||= DeficitGroup.new(semantic_node: node) T.must(@node_deficits[node_name]).branches << branch end |
#add_missed_line(line) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 54 def add_missed_line(line) line_num = line.line_number node = @nodes.reverse.find { |n| line_num.between?(n.start_line, n.end_line) } node_name = node ? node.name : "Line #{line_num}" @node_deficits[node_name] ||= DeficitGroup.new(semantic_node: node) T.must(@node_deficits[node_name]).lines << line end |
#group_missed_branches(file) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 63 def group_missed_branches(file) return unless file.respond_to?(:branches) && file.branches.any? file.missed_branches.each do |branch| add_missed_branch(branch) end end |
#group_missed_lines(file) ⇒ Object
47 48 49 50 51 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 47 def group_missed_lines(file) file.missed_lines.each do |line| add_missed_line(line) end end |
#sort_deficits ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 33 def sort_deficits T.let( @node_deficits.sort_by do |name, group| if (node = group.semantic_node) node.start_line else name.match(/\d+/)&.to_s&.to_i || Float::INFINITY end end.to_h, T::Hash[String, DeficitGroup] ) end |