Class: CvssCli::Metric
- Inherits:
-
Object
- Object
- CvssCli::Metric
- Defined in:
- lib/cvss_cli/metric.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #clear_value ⇒ Object
- #get_numerical_changed_value ⇒ Object
- #get_numerical_value ⇒ Object
- #get_value ⇒ Object
-
#initialize(key, name, desc, values) ⇒ Metric
constructor
A new instance of Metric.
- #set_value(value) ⇒ Object
Constructor Details
#initialize(key, name, desc, values) ⇒ Metric
Returns a new instance of Metric.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cvss_cli/metric.rb', line 8 def initialize(key, name, desc, values) @key = key @name = name @desc = desc @value = nil # todo or add default value? @values = Hash.new values.each do |key, value| @values[key] = Value.new(key, value['name'], value['desc'], value['numerical'], value['numerical_changed']) @value = key if key == 'x' # set default value to Not Defined (X) if the metric has such a value end end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
6 7 8 |
# File 'lib/cvss_cli/metric.rb', line 6 def desc @desc end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/cvss_cli/metric.rb', line 6 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/cvss_cli/metric.rb', line 6 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/cvss_cli/metric.rb', line 6 def value @value end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
6 7 8 |
# File 'lib/cvss_cli/metric.rb', line 6 def values @values end |
Instance Method Details
#clear_value ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/cvss_cli/metric.rb', line 44 def clear_value if @values.values.map { |v| v.key }.include? 'x' @value = 'x' else @value = nil end end |
#get_numerical_changed_value ⇒ Object
39 40 41 42 |
# File 'lib/cvss_cli/metric.rb', line 39 def get_numerical_changed_value return nil if @value.nil? @values[@value].numerical_changed end |
#get_numerical_value ⇒ Object
34 35 36 37 |
# File 'lib/cvss_cli/metric.rb', line 34 def get_numerical_value return nil if @value.nil? @values[@value].numerical end |
#get_value ⇒ Object
29 30 31 32 |
# File 'lib/cvss_cli/metric.rb', line 29 def get_value return nil if @value.nil? @values[@value] end |
#set_value(value) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cvss_cli/metric.rb', line 20 def set_value(value) if @values.keys.include? value.downcase #puts "Setting #{@name}: #{value.upcase}" @value = value.downcase else puts "Value #{value.upcase} not valid for metric #{@name}. Valid values are: #{(@values.values.collect { |v| v.key.upcase }).join(', ')}".red end end |