Class: TextLayout::Table
- Inherits:
-
Object
- Object
- TextLayout::Table
- Defined in:
- lib/text_layout/table.rb
Defined Under Namespace
Instance Method Summary collapse
- #cell_format ⇒ Object
- #column_border_width ⇒ Object
-
#initialize(table, options = {}) ⇒ Table
constructor
A new instance of Table.
- #layout ⇒ Object
- #line_format ⇒ Object
Constructor Details
#initialize(table, options = {}) ⇒ Table
Returns a new instance of Table.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/text_layout/table.rb', line 2 def initialize(table, = {}) @table = table @options = { :align => :auto, :col_border => "|", :row_border => "-", :cross => "+", :border => false, :padding => " " }.merge() if @options[:border] == true @options[:border] = [:top, :bottom, :left, :right, :cell].inject({}){|r, i|r[i] = true;r} end end |
Instance Method Details
#cell_format ⇒ Object
22 23 24 |
# File 'lib/text_layout/table.rb', line 22 def cell_format @cell_format ||= @options[:padding] + "%s" + @options[:padding] end |
#column_border_width ⇒ Object
18 19 20 |
# File 'lib/text_layout/table.rb', line 18 def column_border_width @column_border_width ||= (@options[:padding] + @options[:col_border] + @options[:padding]).display_width end |
#layout ⇒ Object
46 47 48 49 50 51 |
# File 'lib/text_layout/table.rb', line 46 def layout unknot calculate_cell_size build_string.join("\n") end |
#line_format ⇒ Object
26 27 28 |
# File 'lib/text_layout/table.rb', line 26 def line_format @line_format ||= @options[:col_border] + "%s" + @options[:col_border] end |