Sha256: 81548d2a4b5f5b0de2810682e0f75e0b67b227c7ac1ab6df4cb77478b35907f3

Contents?: true

Size: 1.67 KB

Versions: 12

Compression:

Stored size: 1.67 KB

Contents

#!/usr/bin/env ruby

require_relative '../lib/licensee'

path = ARGV[0] || Dir.pwd

# Given a string or object, prepares it for output and human consumption
def humanize(value, type = nil)
  case type
  when :license
    value.name
  when :matcher
    value.class
  when :confidence
    Licensee::ContentHelper.format_percent(value)
  when :method
    value.to_s.tr('_', ' ').capitalize
  else
    value
  end
end

# Methods to call when displaying information about ProjectFiles
MATCHED_FILE_METHODS = %i[
  content_hash attribution confidence matcher license
].freeze

project = Licensee.project(path, detect_packages: true, detect_readme: true)

if project.license
  puts "License: #{project.license.name}"
elsif project.licenses
  puts "Licenses: #{project.licenses.map(&:name)}"
else
  puts 'License: Not detected'
end

puts "Matched files: #{project.matched_files.map(&:filename)}"

project.matched_files.each do |matched_file|
  puts "#{matched_file.filename}:"

  MATCHED_FILE_METHODS.each do |method|
    next unless matched_file.respond_to? method
    value = matched_file.public_send method
    next if value.nil?
    puts "  #{humanize(method, :method)}: #{humanize(value, method)}"
  end

  next unless matched_file.is_a? Licensee::ProjectFiles::LicenseFile
  next unless matched_file.confidence != 100

  matcher = Licensee::Matchers::Dice.new(matched_file)
  licenses = matcher.licenses_by_similiarity
  next if licenses.empty?
  puts '  Closest licenses:'
  licenses[0...3].each do |license, similarity|
    spdx_id = license.meta['spdx-id']
    percent = Licensee::ContentHelper.format_percent(similarity)
    puts "    * #{spdx_id} similarity: #{percent}"
  end
end

exit !project.licenses.empty?

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
licensee-9.8.0 bin/licensee
licensee-9.7.0 bin/licensee
licensee-9.6.0 bin/licensee
licensee-9.5.0 bin/licensee
licensee-9.4.0 bin/licensee
licensee-9.3.1 bin/licensee
licensee-9.3.0 bin/licensee
licensee-9.2.1 bin/licensee
licensee-9.2.0 bin/licensee
licensee-9.1.0 bin/licensee
licensee-9.0.0 bin/licensee
licensee-9.0.0.beta.1 bin/licensee