Class: Spandx::Spdx::Catalogue

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/spandx/spdx/catalogue.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.defaultObject



44
45
46
# File 'lib/spandx/spdx/catalogue.rb', line 44

def default
  from_git
end

.emptyObject



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_gitObject



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

.latest(gateway: ::Spandx::Spdx::Gateway.new) ⇒ Object



27
28
29
# File 'lib/spandx/spdx/catalogue.rb', line 27

def latest(gateway: ::Spandx::Spdx::Gateway.new)
  new(gateway.fetch)
end

Instance Method Details

#[](id) ⇒ Object



12
13
14
# File 'lib/spandx/spdx/catalogue.rb', line 12

def [](id)
  identity_map[id]
end

#eachObject



20
21
22
23
24
# File 'lib/spandx/spdx/catalogue.rb', line 20

def each
  licenses.each do |license|
    yield license
  end
end

#versionObject



16
17
18
# File 'lib/spandx/spdx/catalogue.rb', line 16

def version
  catalogue[:licenseListVersion]
end