Class: Samovar::Output::Columns

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows) ⇒ Columns

Returns a new instance of Columns.



56
57
58
59
# File 'lib/samovar/output.rb', line 56

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

Instance Attribute Details

#widthsObject (readonly)

Returns the value of attribute widths.



61
62
63
# File 'lib/samovar/output.rb', line 61

def widths
  @widths
end

Instance Method Details

#calculate_widths(rows) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/samovar/output.rb', line 63

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