Class: Langfuse::CLI::Formatters::TableFormatter
- Inherits:
-
Object
- Object
- Langfuse::CLI::Formatters::TableFormatter
- Defined in:
- lib/langfuse/cli/formatters/table_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 |
# File 'lib/langfuse/cli/formatters/table_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 rows rows = data.map do |row| headers.map { |header| format_value(row[header]) } end # Create table table = Terminal::Table.new(headings: headers, rows: rows) table.to_s end |