Sha256: bdcf2c52fb7d8362ad51eba6693d2f0c1f3cbf4b5e9f8bdb4012d8a06ce3457c
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
require 'csv' module LicenseFinder class CsvReport < Report COMMA_SEP = "," AVAILABLE_COLUMNS = %w[name version licenses approved summary description] MISSING_DEPENDENCY_TEXT = "This package is not installed. Please install to determine licenses." def initialize(dependencies, options) super @columns = Array(options[:columns]) & AVAILABLE_COLUMNS end def to_s CSV.generate(col_sep: self.class::COMMA_SEP) do |csv| sorted_dependencies.each do |s| csv << format_dependency(s) end end end private def format_dependency(dep) @columns.map do |column| send("format_#{column}", dep) end end def format_name(dep) dep.name end def format_version(dep) dep.version end def format_licenses(dep) if dep.missing? MISSING_DEPENDENCY_TEXT else dep.licenses.map(&:name).join(self.class::COMMA_SEP) end end def format_approved(dep) dep.approved? ? "Approved" : "Not approved" end def format_summary(dep) dep.summary.to_s.strip end def format_description(dep) dep.description.to_s.strip end end end
Version data entries
3 entries across 3 versions & 1 rubygems