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.



7
8
9
10
11
# File 'lib/table_builder/table.rb', line 7

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

Instance Method Details

#add(row) ⇒ Object



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

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



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

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