Class: Zillabyte::Helpers::TableOutputBuilder
- Inherits:
-
Object
- Object
- Zillabyte::Helpers::TableOutputBuilder
- Defined in:
- lib/zillabyte/cli/helpers/table_output_builder.rb
Class Method Summary collapse
- .build_json_table(headings, rows) ⇒ Object
- .build_table(headings, rows, format = nil) ⇒ Object
- .build_terminal_table(headings, rows) ⇒ Object
Class Method Details
.build_json_table(headings, rows) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/zillabyte/cli/helpers/table_output_builder.rb', line 12 def self.build_json_table(headings, rows) out = [] rows.map { |row| h = {} row.each_with_index.map{|x,i| h[headings[i]] = x} out << h } return out.to_json end |
.build_table(headings, rows, format = nil) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/zillabyte/cli/helpers/table_output_builder.rb', line 4 def self.build_table(headings, rows, format = nil) if format == "json" self.build_json_table(headings, rows) else self.build_terminal_table(headings, rows) end end |
.build_terminal_table(headings, rows) ⇒ Object
22 23 24 |
# File 'lib/zillabyte/cli/helpers/table_output_builder.rb', line 22 def self.build_terminal_table(headings, rows) Terminal::Table.new(:headings => headings, :rows => rows).to_s end |