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.



19
20
21
22
# File 'lib/cvss_suite/cvss_property.rb', line 19

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

Instance Method Details

#abbreviationObject

Returns the abbreviation of the property.



34
35
36
# File 'lib/cvss_suite/cvss_property.rb', line 34

def abbreviation
  @property[:abbreviation]
end

#mark_defaultObject

Marks the default value (X / ND) as selected.



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

def mark_default
  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

#mark_selected(abbreviation) ⇒ Object

Marks the value with the given abbreviation as selected.



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

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

  @selected_value = { abbreviation: abbreviation }
end

#nameObject

Returns the full name of the property.



27
28
29
# File 'lib/cvss_suite/cvss_property.rb', line 27

def name
  @property[:name]
end

#non_selected?Boolean

Returns whether a selected_value is set

Returns:



100
101
102
# File 'lib/cvss_suite/cvss_property.rb', line 100

def non_selected?
  @selected_value.nil?
end

#positionObject

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



48
49
50
# File 'lib/cvss_suite/cvss_property.rb', line 48

def position
  @property[:position]
end

#scoreObject

Returns the score of the selected value.



69
70
71
# File 'lib/cvss_suite/cvss_property.rb', line 69

def score
  @selected_value[:weight]
end

#selected_valueObject

Returns the selected value of the property.



55
56
57
# File 'lib/cvss_suite/cvss_property.rb', line 55

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

#valid?Boolean

Returns true if the property is valid.

Returns:



62
63
64
# File 'lib/cvss_suite/cvss_property.rb', line 62

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

#valuesObject

Returns all available values of the property.



41
42
43
# File 'lib/cvss_suite/cvss_property.rb', line 41

def values
  @property[:values]
end