Class: Langfuse::CLI::Formatters::MarkdownFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/langfuse/cli/formatters/markdown_formatter.rb

Class Method Summary collapse

Class Method Details

.format(data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/langfuse/cli/formatters/markdown_formatter.rb', line 7

def self.format(data)
  return "No data to display" if data.nil? || (data.is_a?(Array) && data.empty?)

  # Convert single hash to array for consistent handling
  data = [data] unless data.is_a?(Array)

  # Get all unique keys from all rows
  headers = data.flat_map(&:keys).uniq

  # Build markdown table
  output = []

  # Header row
  output << "| #{headers.join(' | ')} |"

  # Separator row
  output << "| #{headers.map { '---' }.join(' | ')} |"

  # Data rows
  data.each do |row|
    values = headers.map { |header| escape_pipes(format_value(row[header])) }
    output << "| #{values.join(' | ')} |"
  end

  output.join("\n")
end