Class: Text::Table::Cell
- Inherits:
-
Object
- Object
- Text::Table::Cell
- Defined in:
- lib/text-table/cell.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
Text alignment.
-
#colspan ⇒ Object
Positive integer specifying the number of columns spanned.
-
#row ⇒ Object
readonly
:nodoc:.
-
#value ⇒ Object
The object whose
to_s
method is called when rendering the cell.
Instance Method Summary collapse
-
#cell_width ⇒ Object
:nodoc:.
-
#column_index ⇒ Object
:nodoc:.
-
#initialize(options = {}) ⇒ Cell
constructor
:nodoc:.
-
#table ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ Cell
:nodoc:
19 20 21 22 23 24 |
# File 'lib/text-table/cell.rb', line 19 def initialize( = {}) #:nodoc: @value = [:value].to_s @row = [:row] @align = [:align ] || :left @colspan = [:colspan] || 1 end |
Instance Attribute Details
#align ⇒ Object
Text alignment. Acceptable values are :left
(default), :center
and :right
12 13 14 |
# File 'lib/text-table/cell.rb', line 12 def align @align end |
#colspan ⇒ Object
Positive integer specifying the number of columns spanned
16 17 18 |
# File 'lib/text-table/cell.rb', line 16 def colspan @colspan end |
#row ⇒ Object (readonly)
:nodoc:
17 18 19 |
# File 'lib/text-table/cell.rb', line 17 def row @row end |
#value ⇒ Object
The object whose to_s
method is called when rendering the cell.
7 8 9 |
# File 'lib/text-table/cell.rb', line 7 def value @value end |
Instance Method Details
#cell_width ⇒ Object
:nodoc:
45 46 47 |
# File 'lib/text-table/cell.rb', line 45 def cell_width #:nodoc: (0...colspan).map {|i| table.column_widths[column_index + i]}.inject(&:+) + (colspan - 1)*(2*table.horizontal_padding + table.horizontal_boundary.length) end |
#column_index ⇒ Object
:nodoc:
41 42 43 |
# File 'lib/text-table/cell.rb', line 41 def column_index #:nodoc: row.cells[0...row.cells.index(self)].map(&:colspan).inject(0, &:+) end |
#table ⇒ Object
:nodoc:
37 38 39 |
# File 'lib/text-table/cell.rb', line 37 def table #:nodoc: row.table end |
#to_s ⇒ Object
:nodoc:
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/text-table/cell.rb', line 26 def to_s #:nodoc: ([' ' * table.horizontal_padding]*2).join case align when :left value.ljust cell_width when :right value.rjust cell_width when :center value.center cell_width end end |