class Licensee::Matchers::Cran

Constants

GPL_VERSION_REGEX
LICENSE_FIELD_REGEX

While we could parse the DESCRIPTION file, prefer a lenient regex for speed and security. Moar parsing moar problems.

PLUS_FILE_LICENSE_REGEX

Attributes

file[R]

Private Instance Methods

gpl_version(license_key) click to toggle source

returns the normalized GPL version, if the license is a GPL license Otherwise, returns `nil`

# File lib/licensee/matchers/cran.rb, line 27
def gpl_version(license_key)
  match = license_key.match GPL_VERSION_REGEX
  match ? "gpl-#{(match[1] || match[2])}.0" : nil
end
license_field() click to toggle source

Returns the raw license string from the `license: ` field or `nil` if no license field is found

# File lib/licensee/matchers/cran.rb, line 18
def license_field
  return @license_field if defined? @license_field

  match = @file.content.match LICENSE_FIELD_REGEX
  @license_field = match ? match[1].downcase : nil
end
license_property() click to toggle source

Normalizes the license field value to an SPDX ID Rerurns `nil` if no license is found

# File lib/licensee/matchers/cran.rb, line 34
def license_property
  return unless license_field

  # Remove The common + file LICENSE text
  license_key = license_field.sub(PLUS_FILE_LICENSE_REGEX, '')
  gpl_version(license_key) || license_key
end