Class: Exa::CLI::Formatters::ContentsFormatter
- Inherits:
-
Object
- Object
- Exa::CLI::Formatters::ContentsFormatter
- Defined in:
- lib/exa/cli/formatters/contents_formatter.rb
Class Method Summary collapse
Class Method Details
.format(result, format) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/exa/cli/formatters/contents_formatter.rb', line 7 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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/exa/cli/formatters/contents_formatter.rb', line 24 def self.format_pretty(result) output = [] result.results.each_with_index do |content, idx| output << "=== Content #{idx + 1} ===" output << "URL: #{content['url']}" output << "Title: #{content['title']}" output << "" output << "Text:" output << "-" * 40 text = content['text'] || content['content'] || "(No text available)" # Truncate long text to first 500 chars truncated = text.length > 500 ? text[0..500] + "..." : text output << truncated output << "" end output.join("\n") end |
.format_text(result) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/exa/cli/formatters/contents_formatter.rb', line 42 def self.format_text(result) output = [] result.results.each do |content| output << "#{content['url']}\n#{content['text'] || '(No text available)'}" end output.join("\n\n") end |