Class: Licensee::Matchers::Package

Inherits:
Matcher
  • Object
show all
Defined in:
lib/licensee/matchers/package.rb

Overview

Base matcher for package manager metadata files declaring a license.

Direct Known Subclasses

Cabal, Cargo, Cran, DistZilla, Gemspec, NpmBower, NuGet, PyProject, Spdx

Constant Summary collapse

SPDX_SUFFIX_REGEX =

Regex matching SPDX compatibility suffixes that have no matching license entry in the database (e.g. LGPL-3.0-or-later → lgpl-3.0).

/-or-later\z|-only\z/i
SPDX_TOKEN_REGEX =

Regex matching individual SPDX expression tokens (license IDs or operators).

/[A-Za-z0-9.\-+]+/
SPDX_OPERATORS =

SPDX boolean operators to skip when parsing compound expressions.

%w[OR AND WITH].freeze

Constants inherited from Matcher

Matcher::HASH_METHODS

Instance Attribute Summary

Attributes inherited from Matcher

#file

Instance Method Summary collapse

Methods inherited from Matcher

#initialize, #name

Methods included from HashHelper

#serialize_hash_value, #to_h

Constructor Details

This class inherits a constructor from Licensee::Matchers::Matcher

Instance Method Details

#confidenceObject



29
30
31
# File 'lib/licensee/matchers/package.rb', line 29

def confidence
  90
end

#license_propertyObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/licensee/matchers/package.rb', line 43

def license_property
  raise NotImplementedError, "#{self.class}#license_property is not implemented"
end

#matchObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/licensee/matchers/package.rb', line 17

def match
  return @match if defined? @match

  prop = license_property
  return if prop.nil? || prop.to_s.empty?

  licenses = Licensee.licenses(hidden: true)
  @match = licenses.find { |l| l.key == prop }
  @match ||= match_by_spdx_base_key(prop, licenses)
  @match ||= License.find('other')
end

#spdx_expression_licensesObject

Returns all licenses found in a compound SPDX expression such as "MIT OR Apache-2.0". Unknown identifiers resolve to the 'other' (NOASSERTION) license. Returns nil when the property is absent or contains only a single token (plain license key).



37
38
39
40
41
# File 'lib/licensee/matchers/package.rb', line 37

def spdx_expression_licenses
  return @spdx_expression_licenses if defined? @spdx_expression_licenses

  @spdx_expression_licenses = resolve_spdx_expression_licenses
end