Class: Vaulty::Output::Table
- Inherits:
-
Object
- Object
- Vaulty::Output::Table
- Defined in:
- lib/vaulty/output/table.rb
Constant Summary collapse
- DEFAULT_HEADER =
%w(Key Value).freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, header: DEFAULT_HEADER, highlight: {}, prompt:) ⇒ Table
constructor
A new instance of Table.
- #render ⇒ Object
Constructor Details
#initialize(data, header: DEFAULT_HEADER, highlight: {}, prompt:) ⇒ Table
Returns a new instance of Table.
23 24 25 26 27 28 |
# File 'lib/vaulty/output/table.rb', line 23 def initialize(data, header: DEFAULT_HEADER, highlight: {}, prompt:) @data = data @filter = HighlightFilter.new(**highlight) @header = header @prompt = prompt end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
21 22 23 |
# File 'lib/vaulty/output/table.rb', line 21 def data @data end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
21 22 23 |
# File 'lib/vaulty/output/table.rb', line 21 def header @header end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
21 22 23 |
# File 'lib/vaulty/output/table.rb', line 21 def prompt @prompt end |
Class Method Details
.render(*args) ⇒ Object
39 40 41 |
# File 'lib/vaulty/output/table.rb', line 39 def self.render(*args) new(*args).render end |
Instance Method Details
#render ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/vaulty/output/table.rb', line 30 def render table = TTY::Table.new(data, header: header, style: :markdown) renderer = table.render(:ascii, column_widths: [30, 80]) do |render| render.padding = [0, 2, 0, 2] render.filter = @filter end prompt.say renderer end |