Class: CliTable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#column_widthsObject

Returns the value of attribute column_widths.



2
3
4
# File 'lib/ha/cli_table.rb', line 2

def column_widths
  @column_widths
end

#headersObject

Returns the value of attribute headers.



2
3
4
# File 'lib/ha/cli_table.rb', line 2

def headers
  @headers
end

#rowsObject

Returns the value of attribute rows.



2
3
4
# File 'lib/ha/cli_table.rb', line 2

def rows
  @rows
end

Instance Method Details

#add(headers, rows) ⇒ Object



4
5
6
7
# File 'lib/ha/cli_table.rb', line 4

def add(headers, rows)
  @headers = headers
  @rows = rows
end

#header_renderObject



23
24
25
26
27
# File 'lib/ha/cli_table.rb', line 23

def header_render
  result = ""
  @headers.each_index { |i| result << (" %#{column_widths[i]}s" % headers[i]) }
  result
end

#renderObject



14
15
16
17
18
19
20
21
# File 'lib/ha/cli_table.rb', line 14

def render
  result = header_render + "\n"
  @rows.each do
    |row|
    result << row_render(row) + "\n"
  end
  result
end

#resetObject



35
36
37
# File 'lib/ha/cli_table.rb', line 35

def reset
  @rows = []
end

#row_render(row) ⇒ Object



29
30
31
32
33
# File 'lib/ha/cli_table.rb', line 29

def row_render row
  result = ""
  @headers.each_index { |i| result << (" %#{column_widths[i]}s" % format_value(row[i])) }
  result
end

#rows_countObject



9
10
11
# File 'lib/ha/cli_table.rb', line 9

def rows_count
  @rows.length
end