Class: Samovar::Output::Columns

Inherits:
Object
  • Object
show all
Defined in:
lib/samovar/output/columns.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows) ⇒ Columns

Returns a new instance of Columns.



24
25
26
27
# File 'lib/samovar/output/columns.rb', line 24

def initialize(rows)
	@rows = rows
	@widths = calculate_widths(rows)
end

Instance Attribute Details

#widthsObject (readonly)

Returns the value of attribute widths.



29
30
31
# File 'lib/samovar/output/columns.rb', line 29

def widths
  @widths
end

Instance Method Details

#calculate_widths(rows) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/samovar/output/columns.rb', line 31

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