Class: NeverBounce::CLI::Script::Table
- Inherits:
-
Terminal::Table
- Object
- Terminal::Table
- NeverBounce::CLI::Script::Table
- Defined in:
- lib/never_bounce/cli/script/table.rb
Overview
Our custom table class.
Instance Method Summary collapse
-
#align!(headings) ⇒ self
Align table rows according to headings spec.
-
#headings=(ar) ⇒ void
Center-align headings by default.
Instance Method Details
#align!(headings) ⇒ self
Align table rows according to headings spec.
headings = [
["Status", :status],
["Completed", :completed, :right],
["Processing", :processing, :right],
]
table = Table.new(headings: ..., rows: ...).align!(headings)
puts table
NOTE: Invoke after adding row data.
21 22 23 24 25 26 27 28 29 |
# File 'lib/never_bounce/cli/script/table.rb', line 21 def align!(headings) headings.each_with_index do |ar, i| if (v = ar[2]) align_column(i, v) end end self end |
#headings=(ar) ⇒ void
This method returns an undefined value.
Center-align headings by default.
33 34 35 36 37 38 39 40 41 |
# File 'lib/never_bounce/cli/script/table.rb', line 33 def headings=(ar) super(ar.map do |item| if item.is_a? String {value: item, alignment: :center} else item end end) end |