Class: CVESchema::CVE::DataMeta

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

Overview

Represents the "CVE_data_meta" JSON object.

Constant Summary collapse

STATES =
{
  'PUBLIC'      => :PUBLIC,
  'RESERVED'    => :RESERVED,
  'REPLACED_BY' => :REPLACED_BY,
  'SPLIT_FROM'  => :SPLIT_FROM,
  'MERGED_TO'   => :MERGED_TO,
  'REJECT'      => :REJECT
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, assigner:, updated: nil, serial: nil, date_requested: nil, date_assigned: nil, date_public: nil, requester: nil, replaced_by: nil, state: nil, title: nil) ⇒ DataMeta

Initializes the data-meta object.

Parameters:

  • id (ID)
  • assigner (String)
  • updated (DateTime, nil) (defaults to: nil)
  • serial (Integer, nil) (defaults to: nil)
  • date_requested (DateTime, nil) (defaults to: nil)
  • date_assigned (DateTime, nil) (defaults to: nil)
  • date_public (DateTime, nil) (defaults to: nil)
  • requester (String, nil) (defaults to: nil)
  • replaced_by (Array<ID>, nil) (defaults to: nil)
  • state (:PUBLIC, :RESERVED, :REPLACED_BY, :SPLIT_FROM, :MERGED_TO, nil) (defaults to: nil)
  • title (String, nil) (defaults to: nil)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cve_schema/cve/data_meta.rb', line 96

def initialize(id: , assigner: , updated: nil,
                                 serial: nil,
                                 date_requested: nil,
                                 date_assigned: nil,
                                 date_public: nil,
                                 requester: nil,
                                 replaced_by: nil,
                                 state: nil,
                                 title: nil)
  @id       = id
  @assigner = assigner

  @updated        = updated
  @serial         = serial
  @date_requested = date_requested
  @date_assigned  = date_assigned
  @date_public    = date_public
  @requester      = requester
  @replaced_by    = replaced_by
  @state          = state
  @title          = title
end

Instance Attribute Details

#assignerString (readonly)

The assigner's email address.

Returns:

  • (String)


22
23
24
# File 'lib/cve_schema/cve/data_meta.rb', line 22

def assigner
  @assigner
end

#date_assignedDateTime? (readonly)

Date assigned.

Returns:

  • (DateTime, nil)


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

def date_assigned
  @date_assigned
end

#date_publicDateTime? (readonly)

Date published publically.

Returns:

  • (DateTime, nil)


45
46
47
# File 'lib/cve_schema/cve/data_meta.rb', line 45

def date_public
  @date_public
end

#date_requestedDateTime? (readonly)

Date requested.

Returns:

  • (DateTime, nil)


35
36
37
# File 'lib/cve_schema/cve/data_meta.rb', line 35

def date_requested
  @date_requested
end

#idID (readonly)

The CVE ID.

Returns:



17
18
19
# File 'lib/cve_schema/cve/data_meta.rb', line 17

def id
  @id
end

#replaced_byArray<ID>? (readonly)

List of IDs that replaced the CVE.

Returns:

  • (Array<ID>, nil)


55
56
57
# File 'lib/cve_schema/cve/data_meta.rb', line 55

def replaced_by
  @replaced_by
end

#requesterString? (readonly)

Requester email address.

Returns:

  • (String, nil)


50
51
52
# File 'lib/cve_schema/cve/data_meta.rb', line 50

def requester
  @requester
end

#serialInteger? (readonly)

Returns:

  • (Integer, nil)


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

def serial
  @serial
end

#state:PUBLIC, ... (readonly)

Returns:

  • (:PUBLIC, :RESERVED, :REPLACED_BY, :SPLIT_FROM, :MERGED_TO, nil)


67
68
69
# File 'lib/cve_schema/cve/data_meta.rb', line 67

def state
  @state
end

#titleString? (readonly)

Returns:

  • (String, nil)


70
71
72
# File 'lib/cve_schema/cve/data_meta.rb', line 70

def title
  @title
end

#updatedDateTime? (readonly)

Date last updated.

Returns:

  • (DateTime, nil)


27
28
29
# File 'lib/cve_schema/cve/data_meta.rb', line 27

def updated
  @updated
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 Symbol Hash.

Raises:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/cve_schema/cve/data_meta.rb', line 136

def self.from_json(json)
  {
    id: if (id = json['ID'])
          ID.parse(id)
        else
          raise MissingJSONKey.new('ID')
        end,

    assigner: json['ASSIGNER'] || raise(MissingJSONKey.new('ASSIGNER')),

    updated: json['UPDATED'] && Timestamp.parse(json['UPDATED']),
    serial:  json['SERIAL'],
    date_requested: json['DATE_REQUESTED'] && Timestamp.parse(json['DATE_REQUESTED']),
    date_assigned: json['DATE_ASSIGNED'] && Timestamp.parse(json['DATE_ASSIGNED']),
    date_public: json['DATE_PUBLIC'] && Timestamp.parse(json['DATE_PUBLIC']),
    requester: json['REQUESTER'],
    replaced_by: json['REPLACED_BY'] && json['REPLACED_BY'].split(/,\s*/).map { |id| ID.parse(id) },
    state: if json['STATE']
             STATES.fetch(json['STATE']) do
               raise UnknownJSONValue.new('STATE',json['STATE'])
             end
           end,
    title: json['TITLE']
  }
end

.load(json) ⇒ self

Loads the data-meta object from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (self)

    The loaded data-meta object.

Raises:



179
180
181
# File 'lib/cve_schema/cve/data_meta.rb', line 179

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