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

#initialize(width) ⇒ Column

Returns a new instance of Column.



7
8
9
10
11
# File 'lib/make_menu/text/column.rb', line 7

def initialize(width)
  @width = width
  @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 (readonly)

Returns the value of attribute width.



13
14
15
# File 'lib/make_menu/text/column.rb', line 13

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
# File 'lib/make_menu/text/column.rb', line 18

def add(text)
  self.rows += text.split("\n").map do |row|
    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



36
37
38
# File 'lib/make_menu/text/column.rb', line 36

def empty?
  row_index.zero?
end

#heightInteger

Returns The number of rows in the column.

Returns:

  • (Integer)

    The number of rows in the column



31
32
33
# File 'lib/make_menu/text/column.rb', line 31

def height
  row_index
end

#row(index) ⇒ String

Returns The row at the specified index.

Returns:

  • (String)

    The row at the specified index



26
27
28
# File 'lib/make_menu/text/column.rb', line 26

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