Sha256: be6d339e0da0ba589b28fc7de89cd6e0eee54ac446b3a96c17121163a0e7bb40

Contents?: true

Size: 602 Bytes

Versions: 3

Compression:

Stored size: 602 Bytes

Contents

require 'csv'

module LicenseFinder
  class JsonReport < CsvReport
    NEWLINE_SEP = "\n".freeze

    def initialize(dependencies, options)
      super(dependencies, options)
    end

    def to_s
      {dependencies: build_deps}.to_json
    end

    private

    def build_deps
      sorted_dependencies.map do |dep|
        @columns.inject({}) do |memo, column|
          memo[column] = send("format_#{column}", dep)
          memo
        end
      end
    end

    def format_licenses(dep)
      dep.missing? ? [] :
       dep.licenses.map(&(@use_spdx_id ? :standard_id : :name))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
license_finder-7.1.0 lib/license_finder/reports/json_report.rb
license_finder-7.0.1 lib/license_finder/reports/json_report.rb
license_finder-7.0.0 lib/license_finder/reports/json_report.rb