Class: NVD::JSONFeeds::Schema::CVEItem

Inherits:
Object
  • Object
show all
Defined in:
lib/nvd/json_feeds/schema/cve_item.rb

Overview

Represents the "CVE_Item" JSON object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cve:, configurations: nil, impact: nil, published_date: nil, last_modified_date: nil) ⇒ CVEItem

Initializes the CVE Item object.

Parameters:

  • cve (CVESchema::CVE)

    The CVE object.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 37

def initialize(cve: , configurations: nil,
               impact: nil,
               published_date: nil,
               last_modified_date: nil)
  @cve = cve

  @configurations     = configurations
  @impact             = impact
  @published_date     = published_date
  @last_modified_date = last_modified_date
end

Instance Attribute Details

#configurationsConfigurations? (readonly)

Returns:



20
21
22
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 20

def configurations
  @configurations
end

#cveCVESchema::CVE (readonly)

The CVE object.

Returns:

  • (CVESchema::CVE)


17
18
19
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 17

def cve
  @cve
end

#impactImpact? (readonly)

Returns:



23
24
25
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 23

def impact
  @impact
end

#last_modified_dateDateTime? (readonly)

Returns:

  • (DateTime, nil)


29
30
31
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 29

def last_modified_date
  @last_modified_date
end

#published_dateDateTime? (readonly)

Returns:

  • (DateTime, nil)


26
27
28
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 26

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 58

def self.from_json(json)
  {
    cve: CVESchema::CVE.load(json.fetch('cve')),
    configurations: if (configurations = json['configurations'])
                      Configurations.load(configurations)
                    end,
    impact: if (impact = json['impact'])
              Impact.load(impact)
            end,

    published_date: if (published_date = json['publishedDate'])
                      Timestamp.parse(published_date)
                    end,

    last_modified_date: if (last_modified_date = json['lastModifiedDate'])
                          Timestamp.parse(last_modified_date)
                        end
  }
end

.load(json) ⇒ CVEItem

Loads the CVE Item object from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (CVEItem)

    The loaded CVE Item object.



87
88
89
# File 'lib/nvd/json_feeds/schema/cve_item.rb', line 87

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