Class: LicenseScout::SPDX

Inherits:
Object
  • Object
show all
Defined in:
lib/license_scout/spdx.rb

Class Method Summary collapse

Class Method Details

.exceptionsHash

Returns The SPDX license data in Hash form.

Returns:

  • (Hash)

    The SPDX license data in Hash form



52
53
54
# File 'lib/license_scout/spdx.rb', line 52

def exceptions
  @@license_data ||= FFI_Yajl::Parser.parse(File.read(File.expand_path("../data/exceptions.json", __FILE__)))["exceptions"]
end

.find(license_id, force = false) ⇒ String, ...

Try to find the SPDX ID that most closely matches the given license ID

Parameters:

  • license_id (String, nil)

    The license ID

Returns:

  • (String, nil, false)

    Returns either the SPDX ID, false if the license_id was nil, or nil if we could not find a valid SPDX ID



32
33
34
35
36
37
# File 'lib/license_scout/spdx.rb', line 32

def find(license_id, force = false)
  return license_id if force
  return nil if license_id.nil? || %w{ NOASSERTION NONE }.include?(license_id)

  lookup(license_id) || find_by_special_case(license_id) || closest(license_id) || license_id
end

.known_idsObject



56
57
58
# File 'lib/license_scout/spdx.rb', line 56

def known_ids
  @@known_ids ||= licenses.map { |l| l["licenseId"] }
end

.known_namesObject



60
61
62
# File 'lib/license_scout/spdx.rb', line 60

def known_names
  @@known_names ||= licenses.map { |l| l["name"] }
end

.licensesHash

Returns The SPDX license data in Hash form.

Returns:

  • (Hash)

    The SPDX license data in Hash form



47
48
49
# File 'lib/license_scout/spdx.rb', line 47

def licenses
  @@license_data ||= FFI_Yajl::Parser.parse(File.read(File.expand_path("../data/licenses.json", __FILE__)))["licenses"]
end

.parse(license_string) ⇒ Object

Right now this just returns the license keys that are present in the string. In the future, we should handle a proper compound structure like github.com/jslicense/spdx-expression-parse.js



42
43
44
# File 'lib/license_scout/spdx.rb', line 42

def parse(license_string)
  license_string.nil? ? [] : (license_string.tr("()", "").split("\s") - spdx_join_words)
end