Class: CycloneDX::CocoaPods::Pod::License
- Inherits:
-
Object
- Object
- CycloneDX::CocoaPods::Pod::License
- Defined in:
- lib/cyclonedx/cocoapods/license.rb,
lib/cyclonedx/cocoapods/bom_builder.rb
Constant Summary collapse
- SPDX_LICENSES =
JSON.parse(File.read("#{__dir__}/spdx-licenses.json")).freeze
- IDENTIFIER_TYPES =
i[id name].freeze
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#identifier_type ⇒ Object
readonly
Returns the value of attribute identifier_type.
-
#text ⇒ Object
Returns the value of attribute text.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #add_to_bom(xml) ⇒ Object
-
#initialize(identifier:) ⇒ License
constructor
A new instance of License.
- #to_json_component ⇒ Object
Constructor Details
#initialize(identifier:) ⇒ License
Returns a new instance of License.
34 35 36 37 38 39 40 |
# File 'lib/cyclonedx/cocoapods/license.rb', line 34 def initialize(identifier:) raise ArgumentError, 'License identifier must be non-empty' if identifier.nil? || identifier.to_s.strip.empty? @identifier = SPDX_LICENSES.find { |license_id| license_id.downcase == identifier.to_s.downcase } @identifier_type = @identifier.nil? ? :name : :id @identifier ||= identifier end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
31 32 33 |
# File 'lib/cyclonedx/cocoapods/license.rb', line 31 def identifier @identifier end |
#identifier_type ⇒ Object (readonly)
Returns the value of attribute identifier_type.
31 32 33 |
# File 'lib/cyclonedx/cocoapods/license.rb', line 31 def identifier_type @identifier_type end |
#text ⇒ Object
Returns the value of attribute text.
32 33 34 |
# File 'lib/cyclonedx/cocoapods/license.rb', line 32 def text @text end |
#url ⇒ Object
Returns the value of attribute url.
32 33 34 |
# File 'lib/cyclonedx/cocoapods/license.rb', line 32 def url @url end |
Instance Method Details
#add_to_bom(xml) ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/cyclonedx/cocoapods/bom_builder.rb', line 204 def add_to_bom(xml) xml.license do xml.id identifier if identifier_type == :id xml.name_ identifier if identifier_type == :name xml.text_ text unless text.nil? xml.url url unless url.nil? end end |
#to_json_component ⇒ Object
193 194 195 196 197 198 199 200 201 202 |
# File 'lib/cyclonedx/cocoapods/bom_builder.rb', line 193 def to_json_component { license: { id: identifier_type == :id ? identifier : nil, name: identifier_type == :name ? identifier : nil, text: text, url: url }.compact } end |