Class: NVD::JSONFeeds::Schema::CPE::Match

Inherits:
Object
  • Object
show all
Includes:
HasURI
Defined in:
lib/nvd/json_feeds/schema/cpe/match.rb

Overview

Represents the "cpe_match" value.

Instance Attribute Summary collapse

Attributes included from HasURI

#cpe22uri, #cpe23uri

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasURI

included

Constructor Details

#initialize(vulnerable:, version_start_excluding: nil, version_start_including: nil, version_end_excluding: nil, version_end_including: nil, cpe_name: [], **kwargs) ⇒ Match

Initializes the CPE match object.

Parameters:

  • vulnerable (Boolean)
  • version_start_excluding (String, nil) (defaults to: nil)
  • version_start_including (String, nil) (defaults to: nil)
  • version_end_excluding (String, nil) (defaults to: nil)
  • version_end_including (String, nil) (defaults to: nil)
  • cpe_name (Array<Name>) (defaults to: [])


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 47

def initialize(vulnerable: , version_start_excluding: nil,
                             version_start_including: nil,
                             version_end_excluding: nil,
                             version_end_including: nil,
                             cpe_name: [],
                             **kwargs)
  super(**kwargs)

  @vulnerable = vulnerable

  @version_start_excluding = version_start_excluding
  @version_start_including = version_start_including

  @version_end_excluding = version_end_excluding
  @version_end_including = version_end_including

  @cpe_name = cpe_name
end

Instance Attribute Details

#cpe_nameArray<Name> (readonly)

Returns:



30
31
32
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 30

def cpe_name
  @cpe_name
end

#version_end_excludingString? (readonly)

Returns:

  • (String, nil)


24
25
26
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 24

def version_end_excluding
  @version_end_excluding
end

#version_end_includingString? (readonly)

Returns:

  • (String, nil)


27
28
29
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 27

def version_end_including
  @version_end_including
end

#version_start_excludingString? (readonly)

Returns:

  • (String, nil)


18
19
20
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 18

def version_start_excluding
  @version_start_excluding
end

#version_start_includingString? (readonly)

Returns:

  • (String, nil)


21
22
23
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 21

def version_start_including
  @version_start_including
end

#vulnerableBoolean (readonly)

Returns:

  • (Boolean)


15
16
17
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 15

def vulnerable
  @vulnerable
end

Class Method Details

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

Maps the CPE match JSON to a Symbol Hash for #initialize.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Hash{Symbol => Object})

    The mapped Symbol Hash.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 84

def self.from_json(json)
  {
    vulnerable: json.fetch('vulnerable'),

    **super(json),

    version_start_excluding: json['versionStartExcluding'],
    version_start_including: json['versionStartIncluding'],

    version_end_excluding: json['versionEndExcluding'],
    version_end_including: json['versionEndIncluding'],

    cpe_name: Array(json['cpe_name']).map(&Name.method(:load))
  }
end

.load(json) ⇒ Match

Loads the CPE match object from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Match)

    The loaded CPE match object.



109
110
111
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 109

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

Instance Method Details

#vulnerable?Boolean

Determines if the CPE match indicates whether it's vulnerable.

Returns:

  • (Boolean)


71
72
73
# File 'lib/nvd/json_feeds/schema/cpe/match.rb', line 71

def vulnerable?
  @vulnerable == true
end