Class: RTables::Table::MonoTableAlt
- Inherits:
-
RTables::TableBuilder
- Object
- RTables::TableBuilder
- RTables::Table::MonoTableAlt
- Defined in:
- lib/rtables/tables/monotablealt.rb
Instance Attribute Summary
Attributes inherited from RTables::TableBuilder
#columns, #rows, #table_content, #table_header
Instance Method Summary collapse
- #pad(s, len = 32, append = '..') ⇒ Object
- #render ⇒ Object
- #truncuate(s, len = 32, append = '..') ⇒ Object
Methods inherited from RTables::TableBuilder
#add_column, #add_row, #column_exist?, #empty?, #initialize, #inspect, #raise_if_empty, #to_s
Constructor Details
This class inherits a constructor from RTables::TableBuilder
Instance Method Details
#pad(s, len = 32, append = '..') ⇒ Object
52 53 54 55 56 57 |
# File 'lib/rtables/tables/monotablealt.rb', line 52 def pad(s, len = 32, append = '..') s = truncuate(s, len, append) return s if s.length > len s << (' ' * (len - (s.length - 2))) end |
#render ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rtables/tables/monotablealt.rb', line 4 def render corner = '+' line_horizontal = '-' line_vertical = '|' if @table_header.length > 4 column_size = 160 / @table_header.length else column_size = 70 - (@table_header.length * 10) end table = [] rowsep_item_tpl = "#{corner}#{((line_horizontal * (column_size - 2)) << corner) * @table_header.length}" rowsep_tpl = "#{corner}#{line_horizontal * (rowsep_item_tpl.length - 2)}#{corner}" item_tpl = "#{line_vertical} %s " table << rowsep_tpl item = '' @table_header.each do |col| item << pad(item_tpl % col, column_size - 3) end item << line_vertical table << item table << rowsep_item_tpl @table_content.each do |content| item = '' content.each do |col| item << pad(item_tpl % col, column_size - 3) end item << line_vertical table << item end table << rowsep_tpl table end |
#truncuate(s, len = 32, append = '..') ⇒ Object
45 46 47 48 49 50 |
# File 'lib/rtables/tables/monotablealt.rb', line 45 def truncuate(s, len = 32, append = '..') trunc_len = len - append.length - 1 return "#{s[0..trunc_len]}#{append}" if s.length > len s end |