Sha256: f829e903626929ad2235d44361cbb9f7d82d64b08521119211a67e8e9fc86d75

Contents?: true

Size: 876 Bytes

Versions: 3

Compression:

Stored size: 876 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Cli
    module Printers
      class Table < Printer
        HEADINGS = ['Name', 'Version', 'Licenses', 'Location'].freeze

        def initialize
          @spinner = TTY::Spinner.new(output: $stderr)
        end

        def match?(format)
          format.to_sym == :table
        end

        def print_header(_io)
          @dependencies = SortedSet.new
          @spinner.auto_spin
        end

        def print_line(dependency, _io)
          @dependencies << dependency
        end

        def print_footer(io)
          @spinner.stop
          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
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spandx-0.15.0 lib/spandx/cli/printers/table.rb
spandx-0.14.0 lib/spandx/cli/printers/table.rb
spandx-0.13.5 lib/spandx/cli/printers/table.rb