Class: RTables::Table::UnicodeMonoTableAlt
- Inherits:
-
RTables::TableBuilder
- Object
- RTables::TableBuilder
- RTables::Table::UnicodeMonoTableAlt
- Defined in:
- lib/rtables/tables/unicodemonotablealt.rb
Constant Summary collapse
- CORNER_POS_LTOP =
'┌'- CORNER_POS_RTOP =
'┐'- CORNER_POS_MTOP =
'┬'- CORNER_POS_LMID =
'├'- CORNER_POS_RMID =
'┤'- CORNER_POS_MMID =
'┼'- CORNER_POS_LBOT =
'└'- CORNER_POS_RBOT =
'┘'- CORNER_POS_MBOT =
'┴'
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
70 71 72 73 74 75 |
# File 'lib/rtables/tables/unicodemonotablealt.rb', line 70 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
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rtables/tables/unicodemonotablealt.rb', line 16 def render line_horizontal = '─' line_vertical = '│' if @table_header.length > 4 column_size = 160 / @table_header.length else column_size = 70 - (@table_header.length * 10) end row_sep_base = "#{(line_horizontal * (column_size - 2))}%{tchar}" * (@table_header.length) # This needs to be smaller because without, we get one character added too many. row_sep_base_small = row_sep_base[0..row_sep_base.length - 9] row_sep_top = "#{CORNER_POS_LTOP}#{row_sep_base_small % { tchar: CORNER_POS_MTOP }}#{CORNER_POS_RTOP}" row_sep_mid = "#{CORNER_POS_LMID}#{row_sep_base_small % { tchar: CORNER_POS_MMID }}#{CORNER_POS_RMID}" row_sep_bot = "#{CORNER_POS_LBOT}#{row_sep_base_small % { tchar: CORNER_POS_MBOT }}#{CORNER_POS_RBOT}" item_fmt = "#{line_vertical} %s" table = [] table << row_sep_top item = '' @table_header.each do |col| item << pad(item_fmt % col, column_size - 3) end item << line_vertical table << item table << row_sep_mid @table_content.each do |contents| item = '' contents.each do |col| item << pad(item_fmt % col, column_size - 3) end item << line_vertical table << item end table << row_sep_bot table end |
#truncuate(s, len = 32, append = '..') ⇒ Object
63 64 65 66 67 68 |
# File 'lib/rtables/tables/unicodemonotablealt.rb', line 63 def truncuate(s, len = 32, append = '..') trunc_len = len - append.length - 1 return "#{s[0..trunc_len]}#{append}" if s.length > len s end |