Module: Spdx

Defined in:
lib/spdx.rb,
lib/license.rb,
lib/exception.rb,
lib/spdx/version.rb

Defined Under Namespace

Classes: Exception, License

Constant Summary collapse

VERSION =
"4.1.0"

Class Method Summary collapse

Class Method Details

.exception_exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/spdx.rb', line 26

def self.exception_exists?(id)
  exceptions_downcase.key?(id.to_s.downcase)
end

.exceptionsObject



14
15
16
17
18
19
20
# File 'lib/spdx.rb', line 14

def self.exceptions
  @exceptions ||=
    JSON.parse(File.read(File.expand_path("../exceptions.json", __dir__)))["exceptions"]
      .each_with_object({}) do |details, all|
      all[details.delete("licenseExceptionId")] = details
    end
end

.exceptions_downcaseObject



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

def self.exceptions_downcase
  @exceptions_downcase ||= exceptions.keys.each_with_object({}) do |(id, _license), all|
    all[id.downcase] = id
  end
end

.license_exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/spdx.rb', line 22

def self.license_exists?(id)
  licenses_downcase.key?(id.to_s.downcase)
end

.licensesObject



30
31
32
33
34
35
36
# File 'lib/spdx.rb', line 30

def self.licenses
  @licenses ||=
    JSON.parse(File.read(File.expand_path("../licenses.json", __dir__)))["licenses"]
      .each_with_object({}).each do |details, all|
        all[details.delete("licenseId")] = details
      end
end

.licenses_downcaseObject



38
39
40
41
42
# File 'lib/spdx.rb', line 38

def self.licenses_downcase
  @licenses_downcase ||= licenses.keys.each_with_object({}) do |(id, _license), all|
    all[id.downcase] = id
  end
end

.namesObject



10
11
12
# File 'lib/spdx.rb', line 10

def self.names
  (licenses.keys + licenses.map { |_k, v| v["name"] }).sort
end

.normalize(spdx_string, top_level_parens: false) ⇒ Object



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

def self.normalize(spdx_string, top_level_parens: false)
  normalize_tree(SpdxParser.parse(spdx_string), parens: top_level_parens)
end

.parse(spdx_string) ⇒ Object



106
107
108
# File 'lib/spdx.rb', line 106

def self.parse(spdx_string)
  SpdxParser.parse(spdx_string)
end

.valid?(spdx_string) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
# File 'lib/spdx.rb', line 97

def self.valid?(spdx_string)
  return false unless spdx_string.is_a?(String)

  SpdxParser.parse(spdx_string)
  true
rescue SpdxGrammar::SpdxParseError
  false
end