Class: SimpleCov::Formatter::AIFormatter::MarkdownBuilder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
SnippetFormatter
Defined in:
lib/simplecov-ai/markdown_builder.rb,
lib/simplecov-ai/markdown_builder/bypass_compiler.rb,
lib/simplecov-ai/markdown_builder/deficit_grouper.rb,
lib/simplecov-ai/markdown_builder/deficit_compiler.rb,
lib/simplecov-ai/markdown_builder/snippet_formatter.rb

Overview

Responsible for compiling static text representations from evaluated coverage metrics, optimizing layout size, orchestrating string IO buffers, and halting upon token exhaustion. Serves as the primary mutation boundary to format AI consumption targets.

Defined Under Namespace

Modules: SnippetFormatter Classes: BypassCompiler, DeficitCompiler, DeficitGroup, DeficitGrouper

Instance Method Summary collapse

Methods included from SnippetFormatter

#calculate_occurrence, #count_snippet_occurrences, #fetch_snippet_text, #truncate_snippet

Constructor Details

#initialize(result, config) ⇒ MarkdownBuilder

Returns a new instance of MarkdownBuilder.



35
36
37
38
39
40
41
42
# File 'lib/simplecov-ai/markdown_builder.rb', line 35

def initialize(result, config)
  @result = T.let(result, SimpleCov::Result)
  @config = T.let(config, Configuration)
  @buffer = T.let(StringIO.new, StringIO)
  @file_count = T.let(0, Integer)
  @truncated = T.let(false, T::Boolean)
  @ast_cache = T.let({}, T::Hash[String, T::Array[ASTResolver::SemanticNode]])
end

Instance Method Details

#buildObject



49
50
51
52
53
54
55
# File 'lib/simplecov-ai/markdown_builder.rb', line 49

def build
  write_header
  DeficitCompiler.new(@result, @config, self).write_deficits(@buffer)
  BypassCompiler.new(@result, self).write_bypasses(@buffer) if @config.include_bypasses
  write_truncation_warning if @truncated
  @buffer.string
end

#truncate_if_needed?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
# File 'lib/simplecov-ai/markdown_builder.rb', line 65

def truncate_if_needed?
  return false unless @buffer.size / 1024.0 > @config.max_file_size_kb

  @truncated = true
  true
end

#try_resolve_ast(filename) ⇒ Object



58
59
60
61
62
# File 'lib/simplecov-ai/markdown_builder.rb', line 58

def try_resolve_ast(filename)
  @ast_cache[filename] ||= ASTResolver.resolve(filename)
rescue StandardError
  nil
end