Class: KXI::CLI::Table::Column

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

Overview

Represents a column of table

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Column

Instantiates the KXI::CLI::Table::Column class

Parameters:

  • name (string)

    Name of column



60
61
62
63
64
# File 'lib/kxi/cli/table.rb', line 60

def initialize(name)
	@name  = name
	@align = 0
	@data  = []
end

Instance Method Details

#aligninteger

Gets the length of the longest value

Returns:

  • (integer)

    Length of the longest value



48
49
50
# File 'lib/kxi/cli/table.rb', line 48

def align
	@align
end

#namestring

Gets the name of column

Returns:

  • (string)

    Name of column



54
55
56
# File 'lib/kxi/cli/table.rb', line 54

def name
	@name
end

#row(str) ⇒ Object

Adds a row to the column

Parameters:

  • str (string)

    Value of row to add



68
69
70
71
# File 'lib/kxi/cli/table.rb', line 68

def row(str)
	@align = str.length if @align < str.length
	@data.push(str)
end

#write(row) ⇒ Object

Writes the value of a row at given index to stdout

Parameters:

  • row (integer)

    Index of the row to write



75
76
77
78
79
# File 'lib/kxi/cli/table.rb', line 75

def write(row)
	str = @data[row]
	str = '' if str == nil
	print(str.ljust(@align))
end