Class: KiFormat::TableMaker
- Inherits:
-
Object
- Object
- KiFormat::TableMaker
- Defined in:
- lib/ki_format/table_maker.rb
Instance Method Summary collapse
-
#initialize(data, opts = {}) ⇒ TableMaker
constructor
A new instance of TableMaker.
- #print(opts = {}) ⇒ Object
Constructor Details
#initialize(data, opts = {}) ⇒ TableMaker
Returns a new instance of TableMaker.
7 8 9 10 11 12 |
# File 'lib/ki_format/table_maker.rb', line 7 def initialize(data, opts = {}) keys = opts.fetch(:only, nil) @data = data @headings = build_headings(keys) @rows = build_rows end |
Instance Method Details
#print(opts = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ki_format/table_maker.rb', line 14 def print(opts = {}) plain = opts.fetch(:plain, false) table = Terminal::Table.new do |t| t.rows = @rows if plain t.style = {:border_x => "", :border_i => "", :border_y => "", :padding_left => 0, :padding_right => 2} else t.headings = @headings end end str = table.to_s if plain remove_first_blank_line(str) else str end end |