diff options
| author | mo khan <mo.khan@gmail.com> | 2020-06-07 16:20:44 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-06-07 16:20:44 -0600 |
| commit | 747af1f2a3d269c531d9bd462375f8edbb51a25d (patch) | |
| tree | a9366aa8ad2d24a23006ac948a99ad6a1e6013f4 /lib | |
| parent | 42f56de227db4600eae932392c74fe8e0d23a406 (diff) | |
Extract HEADINGS constant and #to_table method
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/spandx/core/table_printer.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/spandx/core/table_printer.rb b/lib/spandx/core/table_printer.rb index 596450a..f77f4ac 100644 --- a/lib/spandx/core/table_printer.rb +++ b/lib/spandx/core/table_printer.rb @@ -3,6 +3,8 @@ module Spandx module Core class TablePrinter < Printer + HEADINGS = ['Name', 'Version', 'Licenses', 'Location'].freeze + def match?(format) format.to_sym == :table end @@ -16,12 +18,15 @@ module Spandx end def print_footer(io) - table = Terminal::Table.new(headings: ['Name', 'Version', 'Licenses', 'Location'], output: io) do |t| - @dependencies.each do |d| - t.add_row d.to_a - end + io.puts(to_table(@dependencies.map(&:to_a))) + end + + private + + def to_table(rows) + Terminal::Table.new(headings: HEADINGS) do |table| + rows.each { |row| table.add_row(row) } end - io.puts(table) end end end |
