Class: MakeMenu::Text::Column
- Inherits:
-
Object
- Object
- MakeMenu::Text::Column
- Defined in:
- lib/make_menu/text/column.rb
Overview
A column of text with a fixed with
Instance Attribute Summary collapse
-
#row_index ⇒ Object
Returns the value of attribute row_index.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#add(text) ⇒ Object
Add a block of text to the column.
-
#empty? ⇒ Boolean
True if the column is empty.
-
#height ⇒ Integer
The number of rows in the column.
-
#initialize ⇒ Column
constructor
A new instance of Column.
-
#row(index) ⇒ String
The row at the specified index.
Constructor Details
#initialize ⇒ Column
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_index ⇒ Object
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 |
#rows ⇒ Object
Returns the value of attribute rows.
15 16 17 |
# File 'lib/make_menu/text/column.rb', line 15 def rows @rows end |
#width ⇒ Object
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.
38 39 40 |
# File 'lib/make_menu/text/column.rb', line 38 def empty? row_index.zero? end |
#height ⇒ Integer
Returns 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.
28 29 30 |
# File 'lib/make_menu/text/column.rb', line 28 def row(index) (rows[index] || '').align(width: width) end |