Class: MakeMenu::Text::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/make_menu/text/column.rb

Overview

A column of text with a fixed with

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeColumn

Returns a new instance of Column.



9
10
11
12
13
# File 'lib/make_menu/text/column.rb', line 9

def initialize
  @width = nil
  @rows = []
  @row_index = 0
end

Instance Attribute Details

#row_indexObject

Returns the value of attribute row_index.



15
16
17
# File 'lib/make_menu/text/column.rb', line 15

def row_index
  @row_index
end

#rowsObject

Returns the value of attribute rows.



15
16
17
# File 'lib/make_menu/text/column.rb', line 15

def rows
  @rows
end

#widthObject

Returns the value of attribute width.



15
16
17
# File 'lib/make_menu/text/column.rb', line 15

def width
  @width
end

Instance Method Details

#add(text) ⇒ Object

Add a block of text to the column. Each row will be padded to the column width



18
19
20
21
22
23
24
25
# File 'lib/make_menu/text/column.rb', line 18

def add(text)
  self.rows += text.split("\n").map do |row|
    self.width = row.decolor.size + SPACING unless width
    self.width = [width, row.decolor.size + SPACING].max
    row.gsub("\r", '')
  end
  self.row_index += text.lines.size
end

#empty?Boolean

Returns True if the column is empty.

Returns:

  • (Boolean)

    True if the column is empty



38
39
40
# File 'lib/make_menu/text/column.rb', line 38

def empty?
  row_index.zero?
end

#heightInteger

Returns The number of rows in the column.

Returns:

  • (Integer)

    The number of rows in the column



33
34
35
# File 'lib/make_menu/text/column.rb', line 33

def height
  row_index
end

#row(index) ⇒ String

Returns The row at the specified index.

Returns:

  • (String)

    The row at the specified index



28
29
30
# File 'lib/make_menu/text/column.rb', line 28

def row(index)
  (rows[index] || '').align(width: width)
end