Class: CVESchema::CVE::Source

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

Overview

Represents the "source" JSON object.

Constant Summary collapse

DISCOVERY =
{
  'INTERNAL' => :INTERNAL,
  'EXTERNAL' => :EXTERNAL,
  'USER'     => :USER,
  'UNKNOWN'  => :UNKNOWN
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(discovery:, defect: nil, advisory: nil) ⇒ Source

Initializes the source object.

Parameters:

  • defect (Array<String>, nil) (defaults to: nil)
  • discovery (:INTERNAL, :EXTERNAL, :USER, :UNKNOWN)
  • advisory (String, nil) (defaults to: nil)


35
36
37
38
39
# File 'lib/cve_schema/cve/source.rb', line 35

def initialize(discovery: , defect: nil, advisory: nil)
  @defect    = defect
  @discovery = discovery
  @advisory  = advisory
end

Instance Attribute Details

#advisoryString? (readonly)

Returns:

  • (String, nil)


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

def advisory
  @advisory
end

#defectArray<String>? (readonly)

Returns:

  • (Array<String>, nil)


11
12
13
# File 'lib/cve_schema/cve/source.rb', line 11

def defect
  @defect
end

#discovery:INTERNAL, ... (readonly)

Returns:

  • (:INTERNAL, :EXTERNAL, :USER, :UNKNOWN)


21
22
23
# File 'lib/cve_schema/cve/source.rb', line 21

def discovery
  @discovery
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.



50
51
52
53
54
55
56
# File 'lib/cve_schema/cve/source.rb', line 50

def self.from_json(json)
  {
    defect:    json['defect'],
    discovery: DISCOVERY[json['discovery']],
    advisory:  json['advisory']
  }
end

.load(json) ⇒ Source

Loads the source from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Source)

    The loaded source object.



69
70
71
# File 'lib/cve_schema/cve/source.rb', line 69

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