Class: CVESchema::CVE::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/cve_schema/cve/product.rb

Overview

Represents a product element within the "product_data" JSON Array.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_name:, version: []) ⇒ Product

Initializes the product.



30
31
32
33
# File 'lib/cve_schema/cve/product.rb', line 30

def initialize(product_name: , version: [])
  @product_name = product_name
  @version      = version
end

Instance Attribute Details

#product_nameString (readonly)

The product name.



14
15
16
# File 'lib/cve_schema/cve/product.rb', line 14

def product_name
  @product_name
end

#versionArray<Version> (readonly) Also known as: versions

The list of affected versions.



19
20
21
# File 'lib/cve_schema/cve/product.rb', line 19

def version
  @version
end

Class Method Details

.from_json(json) ⇒ Hash{Symbol => Object}

Maps the parsed JSON to a Symbol Hash for #initialize.



55
56
57
58
59
60
# File 'lib/cve_schema/cve/product.rb', line 55

def self.from_json(json)
  {
    product_name: json['product_name'],
    version:      Array(json['version']['version_data']).map(&Version.method(:load))
  }
end

.load(json) ⇒ Product

Loads the product object from parsed JSON.



73
74
75
# File 'lib/cve_schema/cve/product.rb', line 73

def self.load(json)
  new(**from_json(json))
end

Instance Method Details

#na?Boolean

Determines if the #product_name is n/a.



40
41
42
# File 'lib/cve_schema/cve/product.rb', line 40

def na?
  @product_name == NA
end