Class: LicenseFinder::CsvReport

Inherits:
Report
  • Object
show all
Defined in:
lib/license_finder/reports/csv_report.rb

Direct Known Subclasses

DiffReport, JsonReport, MergedReport, TextReport

Constant Summary collapse

COMMA_SEP =
','.freeze
NEWLINE_SEP =
'\@NL'.freeze
AVAILABLE_COLUMNS =
%w[name version authors licenses license_links approved summary description homepage install_path package_manager groups texts notice].freeze
MISSING_DEPENDENCY_TEXT =
'This package is not installed. Please install to determine licenses.'.freeze

Instance Method Summary collapse

Methods inherited from Report

of

Constructor Details

#initialize(dependencies, options) ⇒ CsvReport

Returns a new instance of CsvReport.



10
11
12
13
14
15
# File 'lib/license_finder/reports/csv_report.rb', line 10

def initialize(dependencies, options)
  super
  options[:columns] ||= %w[name version licenses]
  @columns = Array(options[:columns]) & self.class::AVAILABLE_COLUMNS
  @write_headers = options[:write_headers] || false
end

Instance Method Details

#to_sObject



17
18
19
20
21
22
23
# File 'lib/license_finder/reports/csv_report.rb', line 17

def to_s
  CSV.generate(col_sep: self.class::COMMA_SEP, headers: @columns, write_headers: @write_headers) do |csv|
    sorted_dependencies.each do |s|
      csv << format_dependency(s)
    end
  end
end