class KXI::CLI::Table
Table
renderer
Public Class Methods
new() { |self| ... }
click to toggle source
Instantiate the {KXI::CLI::Table} class
# File lib/kxi/cli/table.rb, line 8 def initialize @cols = KXI::Collections::ArrayCollection.new @rows = 0 yield(self) if block_given? end
Public Instance Methods
column(name)
click to toggle source
Defines a column of table @param [string] name Name of column @return [KXI::CLI::Table::Column] Defined column
# File lib/kxi/cli/table.rb, line 17 def column(name) col = Column.new(name) @cols.add(col) return col end
render()
click to toggle source
Renders the table into stdout
# File lib/kxi/cli/table.rb, line 32 def render @rows.times do |row| f = true @cols.foreach do |col| print(' ') unless f f = false col.write(row) end puts end end
row(e)
click to toggle source
Adds a row to table @param [Hash<string, any>] e Row to add @return [integer] Current number of rows
# File lib/kxi/cli/table.rb, line 26 def row(e) e.each_key { |c| @cols.first { |i| i.name == c }&.row(e[c].to_s.strip.chomp) } @rows += 1 end