diff options
| author | mo khan <mo.khan@gmail.com> | 2020-06-03 22:21:42 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-06-03 22:21:42 -0600 |
| commit | 24fba02e617594cafbd9ff8094344aead129b017 (patch) | |
| tree | be2050dcd26e6b01ce059b81eaa3bc59028fa180 /lib | |
| parent | 1e4cc139b5c6501a3487a278d0192cce5df7fec5 (diff) | |
Split printers into separate files
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/spandx/core/csv_printer.rb | 15 | ||||
| -rw-r--r-- | lib/spandx/core/json_printer.rb | 15 | ||||
| -rw-r--r-- | lib/spandx/core/printer.rb | 43 | ||||
| -rw-r--r-- | lib/spandx/core/table_printer.rb | 28 |
4 files changed, 58 insertions, 43 deletions
diff --git a/lib/spandx/core/csv_printer.rb b/lib/spandx/core/csv_printer.rb new file mode 100644 index 0000000..319ece5 --- /dev/null +++ b/lib/spandx/core/csv_printer.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Spandx + module Core + class CsvPrinter < Printer + def match?(format) + format.to_sym == :csv + end + + def print_line(dependency, io) + io.puts(CSV.generate_line(dependency.to_a)) + end + end + end +end diff --git a/lib/spandx/core/json_printer.rb b/lib/spandx/core/json_printer.rb new file mode 100644 index 0000000..b385e72 --- /dev/null +++ b/lib/spandx/core/json_printer.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Spandx + module Core + class JsonPrinter < Printer + def match?(format) + format.to_sym == :json + end + + def print_line(dependency, io) + io.puts(Oj.dump(dependency.to_h)) + end + end + end +end diff --git a/lib/spandx/core/printer.rb b/lib/spandx/core/printer.rb index e5b15d9..088a97b 100644 --- a/lib/spandx/core/printer.rb +++ b/lib/spandx/core/printer.rb @@ -23,48 +23,5 @@ module Spandx end end end - - class CsvPrinter < Printer - def match?(format) - format.to_sym == :csv - end - - def print_line(dependency, io) - io.puts(CSV.generate_line(dependency.to_a)) - end - end - - class JsonPrinter < Printer - def match?(format) - format.to_sym == :json - end - - def print_line(dependency, io) - io.puts(Oj.dump(dependency.to_h)) - end - end - - class TablePrinter < Printer - def match?(format) - format.to_sym == :table - end - - def print_header(_io) - @dependencies = SortedSet.new - end - - def print_line(dependency, _io) - @dependencies << dependency - 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 - end - io.puts(table) - end - end end end diff --git a/lib/spandx/core/table_printer.rb b/lib/spandx/core/table_printer.rb new file mode 100644 index 0000000..596450a --- /dev/null +++ b/lib/spandx/core/table_printer.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Spandx + module Core + class TablePrinter < Printer + def match?(format) + format.to_sym == :table + end + + def print_header(_io) + @dependencies = SortedSet.new + end + + def print_line(dependency, _io) + @dependencies << dependency + 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 + end + io.puts(table) + end + end + end +end |
