Module: TTY::Table::Indentation

Defined in:
lib/tty/table/indentation.rb

Overview

A module responsible for indenting table representation

Class Method Summary collapse

Class Method Details

.indent(part, indentation) ⇒ Object

Return a table part with indentation inserted

Parameters:

  • part (#map, #to_s)

    the rendered table part



13
14
15
16
17
18
19
# File 'lib/tty/table/indentation.rb', line 13

def indent(part, indentation)
  if part.is_a?(Enumerable) && part.respond_to?(:to_a)
    part.map { |line| insert_indentation(line, indentation) }
  else
    insert_indentation(part, indentation)
  end
end

.insert_indentation(line, indentation) ⇒ String

Insert indentation into a table renderd line

Parameters:

  • line (String)

    the rendered table line

  • indentation (Integer)

    the amount of indentation to apply

Returns:

  • (String)


32
33
34
# File 'lib/tty/table/indentation.rb', line 32

def insert_indentation(line, indentation)
  line ? " " * indentation + line.to_s : ""
end