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



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

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
# 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



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

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

.known_namesObject



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

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



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

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



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

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