Class: Spandx::Spdx::Catalogue
- Inherits:
-
Object
- Object
- Spandx::Spdx::Catalogue
- Includes:
- Enumerable
- Defined in:
- lib/spandx/spdx/catalogue.rb
Class Method Summary collapse
- .default ⇒ Object
- .empty ⇒ Object
- .from_file(path) ⇒ Object
- .from_git ⇒ Object
- .from_json(json) ⇒ Object
- .latest(gateway: ::Spandx::Spdx::Gateway.new) ⇒ Object
Instance Method Summary collapse
- #[](id) ⇒ Object
- #each ⇒ Object
-
#initialize(catalogue = {}) ⇒ Catalogue
constructor
A new instance of Catalogue.
- #version ⇒ Object
Constructor Details
#initialize(catalogue = {}) ⇒ Catalogue
Returns a new instance of Catalogue.
8 9 10 |
# File 'lib/spandx/spdx/catalogue.rb', line 8 def initialize(catalogue = {}) @catalogue = catalogue end |
Class Method Details
.default ⇒ Object
44 45 46 |
# File 'lib/spandx/spdx/catalogue.rb', line 44 def default from_git end |
.empty ⇒ Object
48 49 50 |
# File 'lib/spandx/spdx/catalogue.rb', line 48 def empty @empty ||= new(licenses: []) end |
.from_file(path) ⇒ Object
35 36 37 |
# File 'lib/spandx/spdx/catalogue.rb', line 35 def from_file(path) from_json(Pathname.new(path).read) end |
.from_git ⇒ Object
39 40 41 42 |
# File 'lib/spandx/spdx/catalogue.rb', line 39 def from_git json = Spandx.git[:spdx].read('json/licenses.json') json ? from_json(json) : latest end |
.from_json(json) ⇒ Object
31 32 33 |
# File 'lib/spandx/spdx/catalogue.rb', line 31 def from_json(json) new(JSON.parse(json, symbolize_names: true)) end |
Instance Method Details
#[](id) ⇒ Object
12 13 14 |
# File 'lib/spandx/spdx/catalogue.rb', line 12 def [](id) identity_map[id] end |
#each ⇒ Object
20 21 22 23 24 |
# File 'lib/spandx/spdx/catalogue.rb', line 20 def each licenses.each do |license| yield license end end |
#version ⇒ Object
16 17 18 |
# File 'lib/spandx/spdx/catalogue.rb', line 16 def version catalogue[:licenseListVersion] end |