Class: Samovar::Output::Columns
- Inherits:
-
Object
- Object
- Samovar::Output::Columns
- Defined in:
- lib/samovar/output/columns.rb
Instance Attribute Summary collapse
-
#widths ⇒ Object
readonly
Returns the value of attribute widths.
Instance Method Summary collapse
- #calculate_widths(rows) ⇒ Object
-
#initialize(rows) ⇒ Columns
constructor
A new instance of Columns.
Constructor Details
#initialize(rows) ⇒ Columns
Returns a new instance of Columns.
9 10 11 12 |
# File 'lib/samovar/output/columns.rb', line 9 def initialize(rows) @rows = rows @widths = calculate_widths(rows) end |
Instance Attribute Details
#widths ⇒ Object (readonly)
Returns the value of attribute widths.
14 15 16 |
# File 'lib/samovar/output/columns.rb', line 14 def widths @widths end |
Instance Method Details
#calculate_widths(rows) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/samovar/output/columns.rb', line 16 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 |