Class: CVESchema::CVE::Vendor

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

Overview

Represents an element within the "vendor_data" JSON Array.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor_name:, product:) ⇒ Vendor

Initializes the vendor object.

Parameters:

  • vendor_name (String)
  • product (Array<Product>)


24
25
26
27
# File 'lib/cve_schema/cve/vendor.rb', line 24

def initialize(vendor_name: , product: )
  @vendor_name = vendor_name
  @product     = product
end

Instance Attribute Details

#productArray<Product> (readonly)

Returns:



15
16
17
# File 'lib/cve_schema/cve/vendor.rb', line 15

def product
  @product
end

#vendor_nameString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/cve_schema/cve/vendor.rb', line 12

def vendor_name
  @vendor_name
end

Class Method Details

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

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

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Hash{Symbol => Object})

    The mapped Symbol Hash.



59
60
61
62
63
64
# File 'lib/cve_schema/cve/vendor.rb', line 59

def self.from_json(json)
  {
    vendor_name: json['vendor_name'],
    product:     json['product']['product_data'].map(&Product.method(:load))
  }
end

.load(json) ⇒ Vendor

Loads the vendor object from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Vendor)

    The loaded vendor object.



77
78
79
# File 'lib/cve_schema/cve/vendor.rb', line 77

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

Instance Method Details

#na?Boolean

Determines if the #vendor_name is n/a.

Returns:

  • (Boolean)


34
35
36
# File 'lib/cve_schema/cve/vendor.rb', line 34

def na?
  @vendor_name == NA
end

#to_sString

Converts the vendor object to a String.

Returns:

  • (String)

    The vendor name



44
45
46
# File 'lib/cve_schema/cve/vendor.rb', line 44

def to_s
  @vendor_name
end