Class: NVD::JSONFeeds::Schema::Impact

Inherits:
Object
  • Object
show all
Defined in:
lib/nvd/json_feeds/schema/impact.rb,
lib/nvd/json_feeds/schema/impact/base_metric_v2.rb,
lib/nvd/json_feeds/schema/impact/base_metric_v3.rb

Overview

Represents the "impact" value.

Defined Under Namespace

Classes: BaseMetricV2, BaseMetricV3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_metric_v3: nil, base_metric_v2: nil) ⇒ Impact

Initializes the impact object.

Parameters:

  • base_metric_v3 (BaseMetricV3, nil) (defaults to: nil)

    The parsed "baseMetricV3" object.

  • base_metric_v2 (BaseMetricV2, nil) (defaults to: nil)

    The parsed "baseMetricV3" object.



31
32
33
34
# File 'lib/nvd/json_feeds/schema/impact.rb', line 31

def initialize(base_metric_v3: nil, base_metric_v2: nil)
  @base_metric_v3 = base_metric_v3
  @base_metric_v2 = base_metric_v2
end

Instance Attribute Details

#base_metric_v2BaseMetricV2? (readonly)

The base metric V2.

Returns:



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

def base_metric_v2
  @base_metric_v2
end

#base_metric_v3BaseMetricV3? (readonly)

The base metric V3.

Returns:



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

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



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nvd/json_feeds/schema/impact.rb', line 45

def self.from_json(json)
  {
    base_metric_v3: if (base_metric_v3 = json['baseMetricV3'])
                      BaseMetricV3.load(base_metric_v3)
                    end,

    base_metric_v2: if (base_metric_v2 = json['baseMetricV2'])
                      BaseMetricV2.load(base_metric_v2)
                    end
  }
end

.load(json) ⇒ Impact

Loads the impact object from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Impact)

    The loaded impact object.



66
67
68
# File 'lib/nvd/json_feeds/schema/impact.rb', line 66

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