Class: Licensee::Matchers::Package
- Defined in:
- lib/licensee/matchers/package.rb
Overview
Base matcher for package manager metadata files declaring a license.
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
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary collapse
- #confidence ⇒ Object
- #license_property ⇒ Object
- #match ⇒ Object
-
#spdx_expression_licenses ⇒ Object
Returns all licenses found in a compound SPDX expression such as "MIT OR Apache-2.0".
Methods inherited from Matcher
Methods included from HashHelper
Constructor Details
This class inherits a constructor from Licensee::Matchers::Matcher
Instance Method Details
#confidence ⇒ Object
29 30 31 |
# File 'lib/licensee/matchers/package.rb', line 29 def confidence 90 end |
#license_property ⇒ Object
43 44 45 |
# File 'lib/licensee/matchers/package.rb', line 43 def license_property raise NotImplementedError, "#{self.class}#license_property is not implemented" end |
#match ⇒ Object
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_licenses ⇒ Object
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 |