Class: Exa::CLI::Formatters::ContextFormatter
- Inherits:
-
Object
- Object
- Exa::CLI::Formatters::ContextFormatter
- Defined in:
- lib/exa/cli/formatters/context_formatter.rb
Class Method Summary collapse
Class Method Details
.format(result, format) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/exa/cli/formatters/context_formatter.rb', line 9 def self.format(result, format) case format when "json" JSON.pretty_generate(result.to_h) when "pretty" format_pretty(result) when "text" format_text(result) when "toon" Exa::CLI::Base.encode_as_toon(result.to_h) else JSON.pretty_generate(result.to_h) end end |
.format_pretty(result) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/exa/cli/formatters/context_formatter.rb', line 26 def self.format_pretty(result) output = [] output << "=" * 60 output << "Query: #{result.query}" output << "=" * 60 output << "" output << "Metadata:" output << " Request ID: #{result.request_id}" output << " Results: #{result.results_count}" output << " Cost: $#{result.cost_dollars}" output << " Search Time: #{result.search_time}ms" output << "" output << "Code Context:" output << "-" * 60 output << result.response.to_s output.join("\n") end |
.format_text(result) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/exa/cli/formatters/context_formatter.rb', line 44 def self.format_text(result) output = [] output << "Query: #{result.query}" output << "Request ID: #{result.request_id}" output << "Results: #{result.results_count}" output << "Cost: $#{result.cost_dollars}" output << "Search Time: #{result.search_time}ms" output << "" output << "Code Context:" output << "-" * 40 output << result.response.to_s output.join("\n") end |