module TTY::Table::Indentation

A module responsible for indenting table representation

Public Class Methods

indent(part, indentation) click to toggle source

Return a table part with indentation inserted

@param [#map, to_s] part

the rendered table part

@api public

# File lib/tty/table/indentation.rb, line 13
def indent(part, indentation)
  if part.respond_to?(:to_a)
    part.map { |line| insert_indentation(line, indentation) }
  else
    insert_indentation(part, indentation)
  end
end
insert_indentation(line, indentation) click to toggle source

Insert indentation into a table renderd line

@param [#to_a, to_s] line

the rendered table line

@api public

# File lib/tty/table/indentation.rb, line 28
def insert_indentation(line, indentation)
  line = line.is_a?(Array) ? line[0] : line
  line.insert(0, ' ' * indentation) if line
end