Class: LicenseScout::SPDX
- Inherits:
-
Object
- Object
- LicenseScout::SPDX
- Defined in:
- lib/license_scout/spdx.rb
Class Method Summary collapse
-
.exceptions ⇒ Hash
The SPDX license data in Hash form.
-
.find(license_id, force = false) ⇒ String, ...
Try to find the SPDX ID that most closely matches the given license ID.
- .known_ids ⇒ Object
- .known_names ⇒ Object
-
.licenses ⇒ Hash
The SPDX license data in Hash form.
-
.parse(license_string) ⇒ Object
Right now this just returns the license keys that are present in the string.
Class Method Details
.exceptions ⇒ Hash
Returns 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.("../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
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_ids ⇒ Object
56 57 58 |
# File 'lib/license_scout/spdx.rb', line 56 def known_ids @@known_ids ||= licenses.map { |l| l["licenseId"] } end |
.known_names ⇒ Object
60 61 62 |
# File 'lib/license_scout/spdx.rb', line 60 def known_names @@known_names ||= licenses.map { |l| l["name"] } end |
.licenses ⇒ Hash
Returns 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.("../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 |