class Samovar::Output::Columns
Represents column widths for aligned output formatting.
Calculates the maximum width of each column across all rows for proper text alignment.
Attributes
The calculated column widths.
@attribute [Array(Integer)]
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/columns.rb, line 21 def initialize(rows) @rows = rows @widths = calculate_widths(rows) end
Initialize column width calculator.
@parameter rows [Array(Array)] The rows to calculate column widths from.
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/output/columns.rb, line 35 def calculate_widths(rows) widths = [] rows.each do |row| row.each.with_index do |column, index| (widths[index] ||= []) << column.size end end return widths.collect(&:max) end
Calculate the maximum width for each column.
@parameter rows [Array(Array)] The rows to analyze. @returns [Array(Integer)] The maximum width of each column.