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
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) ⇒ Column
constructor
A new instance of Column.
-
#row(index) ⇒ String
The row at the specified index.
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_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
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.
36 37 38 |
# File 'lib/make_menu/text/column.rb', line 36 def empty? row_index.zero? end |
#height ⇒ Integer
Returns 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.
26 27 28 |
# File 'lib/make_menu/text/column.rb', line 26 def row(index) (rows[index] || '').align(width: width) end |