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.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) click to toggle source

Insert indentation into a table renderd line

@param [String] line

the rendered table line

@param [Integer] indentation

the amount of indentation to apply

@return [String]

@api public

# File lib/tty/table/indentation.rb, line 32
def insert_indentation(line, indentation)
  line ? " " * indentation + line.to_s : ""
end

Private Instance 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.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) click to toggle source

Insert indentation into a table renderd line

@param [String] line

the rendered table line

@param [Integer] indentation

the amount of indentation to apply

@return [String]

@api public

# File lib/tty/table/indentation.rb, line 32
def insert_indentation(line, indentation)
  line ? " " * indentation + line.to_s : ""
end