Class: TTY::Table::Indentation

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

Overview

A class responsible for indenting table representation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(renderer) ⇒ Indentation

Initialize an Indentation



13
14
15
# File 'lib/tty/table/indentation.rb', line 13

def initialize(renderer)
  @renderer = renderer
end

Instance Attribute Details

#rendererObject (readonly)

Returns the value of attribute renderer.



8
9
10
# File 'lib/tty/table/indentation.rb', line 8

def renderer
  @renderer
end

Instance Method Details

#indentationObject

Create indentation



20
21
22
# File 'lib/tty/table/indentation.rb', line 20

def indentation
  ' ' * renderer.indent
end

#insert_indent(part) ⇒ Object

Return a table part with indentation inserted

Parameters:

  • part (#map, #to_s)

    the rendered table part



30
31
32
33
34
35
36
# File 'lib/tty/table/indentation.rb', line 30

def insert_indent(part)
  if part.respond_to?(:to_a)
    part.map { |line| insert_indentation(line) }
  else
    insert_indentation(part)
  end
end