Class: Sbom::Data::Sbom
- Inherits:
-
Object
- Object
- Sbom::Data::Sbom
- Defined in:
- lib/sbom/data/sbom.rb
Instance Attribute Summary collapse
-
#bom_version ⇒ Object
Returns the value of attribute bom_version.
-
#sbom_type ⇒ Object
Returns the value of attribute sbom_type.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #add_annotation(annotation) ⇒ Object
- #add_annotations(annotations_list) ⇒ Object
- #add_document(doc) ⇒ Object
- #add_file(file) ⇒ Object
- #add_files(files_hash) ⇒ Object
- #add_license(license) ⇒ Object
- #add_licenses(licenses_list) ⇒ Object
- #add_package(package) ⇒ Object
- #add_packages(packages_hash) ⇒ Object
- #add_property(name, value) ⇒ Object
- #add_relationship(relationship) ⇒ Object
- #add_relationships(relationships_list) ⇒ Object
- #annotations ⇒ Object
- #document ⇒ Object
- #document=(doc) ⇒ Object
- #files ⇒ Object
-
#initialize(sbom_type: :auto) ⇒ Sbom
constructor
A new instance of Sbom.
- #licenses ⇒ Object
- #packages ⇒ Object
- #properties ⇒ Object
- #relationships ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(sbom_type: :auto) ⇒ Sbom
Returns a new instance of Sbom.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sbom/data/sbom.rb', line 8 def initialize(sbom_type: :auto) @sbom_type = sbom_type @document = nil @files = {} @packages = {} @relationships = [] @licenses = [] @annotations = [] @properties = [] end |
Instance Attribute Details
#bom_version ⇒ Object
Returns the value of attribute bom_version.
6 7 8 |
# File 'lib/sbom/data/sbom.rb', line 6 def bom_version @bom_version end |
#sbom_type ⇒ Object
Returns the value of attribute sbom_type.
6 7 8 |
# File 'lib/sbom/data/sbom.rb', line 6 def sbom_type @sbom_type end |
#uuid ⇒ Object
Returns the value of attribute uuid.
6 7 8 |
# File 'lib/sbom/data/sbom.rb', line 6 def uuid @uuid end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/sbom/data/sbom.rb', line 6 def version @version end |
Instance Method Details
#add_annotation(annotation) ⇒ Object
88 89 90 |
# File 'lib/sbom/data/sbom.rb', line 88 def add_annotation(annotation) @annotations << annotation end |
#add_annotations(annotations_list) ⇒ Object
92 93 94 |
# File 'lib/sbom/data/sbom.rb', line 92 def add_annotations(annotations_list) @annotations.concat(annotations_list) if annotations_list.is_a?(Array) end |
#add_document(doc) ⇒ Object
27 28 29 |
# File 'lib/sbom/data/sbom.rb', line 27 def add_document(doc) @document = doc.is_a?(Hash) ? doc : doc&.to_h end |
#add_file(file) ⇒ Object
35 36 37 38 39 |
# File 'lib/sbom/data/sbom.rb', line 35 def add_file(file) data = file.is_a?(Hash) ? file : file.to_h key = data[:name] @files[key] = data if key end |
#add_files(files_hash) ⇒ Object
41 42 43 |
# File 'lib/sbom/data/sbom.rb', line 41 def add_files(files_hash) @files.merge!(files_hash) if files_hash.is_a?(Hash) && files_hash.any? end |
#add_license(license) ⇒ Object
76 77 78 |
# File 'lib/sbom/data/sbom.rb', line 76 def add_license(license) @licenses << license end |
#add_licenses(licenses_list) ⇒ Object
80 81 82 |
# File 'lib/sbom/data/sbom.rb', line 80 def add_licenses(licenses_list) @licenses.concat(licenses_list) if licenses_list.is_a?(Array) end |
#add_package(package) ⇒ Object
49 50 51 52 53 |
# File 'lib/sbom/data/sbom.rb', line 49 def add_package(package) data = package.is_a?(Hash) ? package : package.to_h key = [data[:name], data[:version]] @packages[key] = data if data[:name] end |
#add_packages(packages_hash) ⇒ Object
55 56 57 |
# File 'lib/sbom/data/sbom.rb', line 55 def add_packages(packages_hash) @packages.merge!(packages_hash) if packages_hash.is_a?(Hash) && packages_hash.any? end |
#add_property(name, value) ⇒ Object
96 97 98 |
# File 'lib/sbom/data/sbom.rb', line 96 def add_property(name, value) @properties << [name.strip, value] end |
#add_relationship(relationship) ⇒ Object
63 64 65 66 |
# File 'lib/sbom/data/sbom.rb', line 63 def add_relationship(relationship) data = relationship.is_a?(Hash) ? relationship : relationship.to_h @relationships << data end |
#add_relationships(relationships_list) ⇒ Object
68 69 70 |
# File 'lib/sbom/data/sbom.rb', line 68 def add_relationships(relationships_list) @relationships.concat(relationships_list) if relationships_list.is_a?(Array) end |
#annotations ⇒ Object
84 85 86 |
# File 'lib/sbom/data/sbom.rb', line 84 def annotations @annotations end |
#document ⇒ Object
19 20 21 |
# File 'lib/sbom/data/sbom.rb', line 19 def document @document end |
#document=(doc) ⇒ Object
23 24 25 |
# File 'lib/sbom/data/sbom.rb', line 23 def document=(doc) @document = doc.is_a?(Hash) ? doc : doc&.to_h end |
#files ⇒ Object
31 32 33 |
# File 'lib/sbom/data/sbom.rb', line 31 def files @files.values end |
#licenses ⇒ Object
72 73 74 |
# File 'lib/sbom/data/sbom.rb', line 72 def licenses @licenses end |
#packages ⇒ Object
45 46 47 |
# File 'lib/sbom/data/sbom.rb', line 45 def packages @packages.values end |
#properties ⇒ Object
100 101 102 |
# File 'lib/sbom/data/sbom.rb', line 100 def properties @properties end |
#relationships ⇒ Object
59 60 61 |
# File 'lib/sbom/data/sbom.rb', line 59 def relationships @relationships end |
#to_h ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/sbom/data/sbom.rb', line 104 def to_h result = { type: @sbom_type, version: @version, uuid: @uuid, bom_version: @bom_version } result[:document] = @document if @document result[:files] = @files if @files.any? result[:packages] = @packages if @packages.any? result[:relationships] = @relationships if @relationships.any? result[:licenses] = @licenses if @licenses.any? result[:annotations] = @annotations if @annotations.any? result[:properties] = @properties if @properties.any? result.compact end |