Class: TableBuilder::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/table_builder/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(min_column_size) ⇒ Table

Returns a new instance of Table.



5
6
7
8
9
# File 'lib/table_builder/table.rb', line 5

def initialize(min_column_size)
  @rows = []
  @header_column_sizes = []
  @min_column_size = min_column_size
end

Instance Method Details

#add(row) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/table_builder/table.rb', line 11

def add(row)
  # Means the header
  if @rows.size.zero?
    set_header_column_size(row)

  else
    if row.columns.size != @header_column_sizes.size
      fail "Bud number of columns (#{row.columns.size} for #{@header_column_sizes.size})"
    end
  end

  @rows << row
end

#to_sObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/table_builder/table.rb', line 25

def to_s
  puts separate

  @rows.each.with_index do |row, index|
    puts format_line(row)
    puts separate if index != @rows.size - 1
  end

  puts separate
end