module Tablez
  class Display

    attr_reader :table

    def initialize(table)
      @table = table
    end

    def display!
      ''.tap do |t|
        t << separator.render
        table.rows.each_with_index do |r, i|
          t << '|'
          t << r.render(table)
          t << separator.render unless i == table.rows.size - 1
        end
        t << separator.bottom
      end
    end

    def separator
      Separator.new(table)
    end
  end
end
