Class: Table

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

Instance Method Summary collapse

Constructor Details

#initialize(header, rows) ⇒ Table

Returns a new instance of Table.



2
3
4
5
6
# File 'lib/table.rb', line 2

def initialize(header, rows)
  @header = header
  @rows = rows
  @column_sizes = calculate_column_sizes
end

Instance Method Details

#to_sObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/table.rb', line 8

def to_s
  lines = [
    separator_line,
    header_line,
    separator_line,
    @rows.map { |r| row_line(r) },
    separator_line,
  ]

  lines
    .flatten
    .reject { |line| line.empty? }
    .join("\n")
end