Class: MakeMenu::TextColumn
- Inherits:
-
Object
- Object
- MakeMenu::TextColumn
- 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
readonly
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(width) ⇒ TextColumn
constructor
A new instance of TextColumn.
-
#row(index) ⇒ String
Return the specified row of text.
Constructor Details
#initialize(width) ⇒ TextColumn
Returns a new instance of TextColumn.
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_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 (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
19 20 21 22 23 24 |
# File 'lib/make_menu/text_column.rb', line 19 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.
39 40 41 |
# File 'lib/make_menu/text_column.rb', line 39 def empty? row_index.zero? end |
#height ⇒ Integer
Returns The number of rows in the column.
34 35 36 |
# File 'lib/make_menu/text_column.rb', line 34 def height row_index end |
#row(index) ⇒ String
Return the specified row of text
29 30 31 |
# File 'lib/make_menu/text_column.rb', line 29 def row(index) (rows[index] || '').align(width: width) end |