Class: RailsAiBridge::Tools::SearchCode::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/search_code/formatter.rb

Overview

Formats the search results into a markdown string.

Instance Method Summary collapse

Instance Method Details

#call(results, pattern, path) ⇒ String

Returns The formatted markdown output.

Parameters:

  • results (Array<Hash>)

    Array of search results.

  • pattern (String)

    The search pattern used.

  • path (String, nil)

    The path searched within.

Returns:

  • (String)

    The formatted markdown output.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails_ai_bridge/tools/search_code/formatter.rb', line 12

def call(results, pattern, path)
  if results.empty?
    return "No results found for '#{pattern}'#{" in #{path}" if path}."
  end

  output = results.map { |r| "#{r[:file]}:#{r[:line_number]}: #{r[:content].strip}" }.join("\n")
  header = "# Search: `#{pattern}`
**#{results.size} results**#{" in #{path}" if path}

```
"
  footer = "
```"

  "#{header}#{output}#{footer}"
end