Class: PostRunner::FlexiTable::Cell
- Inherits:
-
Object
- Object
- PostRunner::FlexiTable::Cell
- Defined in:
- lib/postrunner/FlexiTable.rb
Instance Method Summary collapse
-
#initialize(table, row, content, attributes) ⇒ Cell
constructor
A new instance of Cell.
- #min_terminal_width ⇒ Object
- #set_indicies(col_idx, row_idx) ⇒ Object
- #to_html(doc) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(table, row, content, attributes) ⇒ Cell
Returns a new instance of Cell.
35 36 37 38 39 40 41 42 43 |
# File 'lib/postrunner/FlexiTable.rb', line 35 def initialize(table, row, content, attributes) @table = table @row = row @content = content @attributes = attributes @column_index = nil @row_index = nil end |
Instance Method Details
#min_terminal_width ⇒ Object
45 46 47 |
# File 'lib/postrunner/FlexiTable.rb', line 45 def min_terminal_width @content.to_s.length end |
#set_indicies(col_idx, row_idx) ⇒ Object
49 50 51 52 |
# File 'lib/postrunner/FlexiTable.rb', line 49 def set_indicies(col_idx, row_idx) @column_index = col_idx @row_index = row_idx end |
#to_html(doc) ⇒ Object
72 73 74 75 |
# File 'lib/postrunner/FlexiTable.rb', line 72 def to_html(doc) doc.td(@content.respond_to?('to_html') ? @content.to_html(doc) : @content.to_s) end |
#to_s ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/postrunner/FlexiTable.rb', line 54 def to_s s = @content.to_s width = get_attribute(:min_terminal_width) case get_attribute(:halign) when :left, nil s + ' ' * (width - s.length) when :right ' ' * (width - s.length) + s when :center w = width - s.length left_padding = w / 2 right_padding = w / 2 + w % 2 ' ' * left_padding + s + ' ' * right_padding else raise "Unknown alignment" end end |