Class: Kosi::Table

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

Overview

Table

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Table

Returns a new instance of Table.



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

def initialize(options = {})
  @align = Kosi::Align.new(options)
  @header = Kosi::Header.new(options)
  @connector_char = Kosi::ConnectorChar.new(options)
  @horizontal_border_char = Kosi::HorizontalBorderChar.new(options)
  @vertical_border_char = Kosi::VerticalBorderChar.new(options)
  @separate_each_row = Kosi::SeparateEachRow.new(options)
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



10
11
12
# File 'lib/table.rb', line 10

def align
  @align
end

#connector_charObject (readonly)

Returns the value of attribute connector_char.



10
11
12
# File 'lib/table.rb', line 10

def connector_char
  @connector_char
end

#headerObject (readonly)

Returns the value of attribute header.



10
11
12
# File 'lib/table.rb', line 10

def header
  @header
end

#horizontal_border_charObject (readonly)

Returns the value of attribute horizontal_border_char.



10
11
12
# File 'lib/table.rb', line 10

def horizontal_border_char
  @horizontal_border_char
end

#separate_each_rowObject (readonly)

Returns the value of attribute separate_each_row.



10
11
12
# File 'lib/table.rb', line 10

def separate_each_row
  @separate_each_row
end

#vertical_border_charObject (readonly)

Returns the value of attribute vertical_border_char.



10
11
12
# File 'lib/table.rb', line 10

def vertical_border_char
  @vertical_border_char
end

Instance Method Details

#render(rows) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/table.rb', line 22

def render(rows)
  check_rows_type(rows)
  check_each_array_length(rows)
  header = read_header
  escaped_rows = escape_ansi_escape_sequence(rows)
  max_lengths = get_max_lengths(escaped_rows, header)
  table_format_rows = get_table_format_rows(rows, max_lengths, header)
  table_format_rows.join("\n") + "\n"
end