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
- #group_missed_branches(file) ⇒ Object
- #group_missed_lines(file) ⇒ Object
-
#initialize(nodes) ⇒ DeficitGrouper
constructor
A new instance of DeficitGrouper.
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.node_deficits end |
Instance Method Details
#add_missed_branch(branch) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 53 def add_missed_branch(branch) start_line = branch.start_line end_line = branch.end_line node = @nodes.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 |
#group_missed_branches(file) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 44 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
33 34 35 36 37 38 39 40 41 |
# File 'lib/simplecov-ai/markdown_builder/deficit_grouper.rb', line 33 def group_missed_lines(file) file.missed_lines.each do |line| line_num = line.line_number node = @nodes.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 end |