Class: CvssSuite::CvssProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/cvss_suite/cvss_property.rb

Overview

This class represents a CVSS property of a CVSS metric.

Instance Method Summary collapse

Constructor Details

#initialize(property) ⇒ CvssProperty

Creates a new CVSS property by a property.

Property needs to consist of a name, a abbreviation, the possible positions in the CVSS vector, a weight, and the available values for the property.



17
18
19
20
# File 'lib/cvss_suite/cvss_property.rb', line 17

def initialize(property)
  @property = property
  @property[:default_value] ||= 'Not Defined'
end

Instance Method Details

#abbreviationObject

Returns the abbreviation of the property.



32
33
34
# File 'lib/cvss_suite/cvss_property.rb', line 32

def abbreviation
  @property[:abbreviation]
end

#nameObject

Returns the full name of the property.



25
26
27
# File 'lib/cvss_suite/cvss_property.rb', line 25

def name
  @property[:name]
end

#non_selected?Boolean

Returns whether a selected_value is set

Returns:

  • (Boolean)


98
99
100
# File 'lib/cvss_suite/cvss_property.rb', line 98

def non_selected?
  @selected_value.nil?
end

#positionObject

Returns the possible positions in the CVSS vector of the property.



46
47
48
# File 'lib/cvss_suite/cvss_property.rb', line 46

def position
  @property[:position]
end

#scoreObject

Returns the score of the selected value.



67
68
69
# File 'lib/cvss_suite/cvss_property.rb', line 67

def score
  @selected_value[:weight]
end

#selected_valueObject

Returns the selected value of the property.



53
54
55
# File 'lib/cvss_suite/cvss_property.rb', line 53

def selected_value
  @selected_value || @property[:default_value]
end

#set_default_valueObject

Sets the default value.



87
88
89
90
91
92
93
# File 'lib/cvss_suite/cvss_property.rb', line 87

def set_default_value
  values.each do |value|
    value[:selected] = value[:abbreviation].eql?('X')
    value[:selected] ||= value[:abbreviation].eql?('ND')
  end
  @selected_value = values.detect { |value| value[:selected] }
end

#set_selected_value(selected_value) ⇒ Object

Sets the selected value by a value.



74
75
76
77
78
79
80
81
82
# File 'lib/cvss_suite/cvss_property.rb', line 74

def set_selected_value(selected_value)
  values.each do |value|
    value[:selected] = selected_value.eql?(value[:abbreviation])
  end
  @selected_value = values.detect { |value| value[:selected] }
  return unless @selected_value.nil?

  @selected_value = { abbreviation: selected_value }
end

#valid?Boolean

Returns true if the property is valid.

Returns:

  • (Boolean)


60
61
62
# File 'lib/cvss_suite/cvss_property.rb', line 60

def valid?
  !@selected_value.nil? && @property[:values].map { |p| p[:abbreviation] }.include?(@selected_value[:abbreviation])
end

#valuesObject

Returns all available values of the property.



39
40
41
# File 'lib/cvss_suite/cvss_property.rb', line 39

def values
  @property[:values]
end