Class: Clin::Text::TableRow
- Inherits:
-
Object
- Object
- Clin::Text::TableRow
- Includes:
- Enumerable
- Defined in:
- lib/clin/text/table.rb
Overview
Table Row container class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cells ⇒ Object
List of cells in the row.
Instance Method Summary collapse
- #border(text, separator = '') ⇒ Object
-
#delimiter_at(index) ⇒ Object
Get the delimiter to insert after the cell at
indexWill return the corresponding delimiter and for the last cell will return ''. - #each(&block) ⇒ Object
-
#initialize(table, cells) ⇒ TableRow
constructor
A new instance of TableRow.
- #to_s ⇒ Object
Constructor Details
#initialize(table, cells) ⇒ TableRow
Returns a new instance of TableRow.
161 162 163 164 |
# File 'lib/clin/text/table.rb', line 161 def initialize(table, cells) @table = table @cells = cells.flatten.each_with_index.map { |x, i| TableCell.new(table, i, x) } end |
Instance Attribute Details
#cells ⇒ Object
List of cells in the row.
159 160 161 |
# File 'lib/clin/text/table.rb', line 159 def cells @cells end |
Instance Method Details
#border(text, separator = '') ⇒ Object
172 173 174 175 |
# File 'lib/clin/text/table.rb', line 172 def border(text, separator = '') return text unless @table.border? @table.vertical_border + separator + text + separator + @table.vertical_border end |
#delimiter_at(index) ⇒ Object
Get the delimiter to insert after the cell at index
Will return the corresponding delimiter and for the last cell will return ''
180 181 182 183 184 185 186 |
# File 'lib/clin/text/table.rb', line 180 def delimiter_at(index) delim = @table.delimiter_at(index) if !@table.separate_blank? && (@cells[index].blank? || @cells[index + 1].blank?) delim = ' ' * delim.size end delim end |
#each(&block) ⇒ Object
166 167 168 169 170 |
# File 'lib/clin/text/table.rb', line 166 def each(&block) @table.column_length.size.times.each do |i| block.call(@cells[i] || '') end end |
#to_s ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/clin/text/table.rb', line 188 def to_s out = '' each_with_index do |cell, i| out << cell.to_s out << delimiter_at(i) end border(out, ' ') end |