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.



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

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

Instance Method Details

#abbreviationObject

Returns the abbreviation of the property.



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

def abbreviation
  @property[:abbreviation]
end

#nameObject

Returns the full name of the property.



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

def name
  @property[:name]
end

#positionObject

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



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

def position
  @property[:position]
end

#scoreObject

Returns the score of the selected value.



73
74
75
# File 'lib/cvss_suite/cvss_property.rb', line 73

def score
  @selected_value[:weight]
end

#selected_valueObject

Returns the selected value of the property.



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

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

#set_default_valueObject

Sets the default value.



90
91
92
93
94
95
# File 'lib/cvss_suite/cvss_property.rb', line 90

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

#set_selected_value(selected_value) ⇒ Object

Sets the selected value by a value.



80
81
82
83
84
85
# File 'lib/cvss_suite/cvss_property.rb', line 80

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] }
end

#valid?Boolean

Returns true if the property is valid.

Returns:

  • (Boolean)


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

def valid?
  !@selected_value.nil?
end

#valuesObject

Returns all available values of the property.



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

def values
  @property[:values]
end