Class: CvssCli::MetricGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/cvss_cli/metric_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, metrics) ⇒ MetricGroup

Returns a new instance of MetricGroup.



9
10
11
12
13
14
15
16
# File 'lib/cvss_cli/metric_group.rb', line 9

def initialize(name, metrics)
  @name = name
  @metrics = Hash.new

  metrics.each do |key, metric|
    @metrics[key] = Metric.new(key, metric['name'], metric['desc'], metric['values'])
  end
end

Instance Attribute Details

#metricsObject (readonly)

Returns the value of attribute metrics.



7
8
9
# File 'lib/cvss_cli/metric_group.rb', line 7

def metrics
  @metrics
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/cvss_cli/metric_group.rb', line 6

def name
  @name
end

Instance Method Details

#all_metrics_set?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/cvss_cli/metric_group.rb', line 55

def all_metrics_set?
  !@metrics.values.any? { |m| m.value.nil? }
end

#any_metric_set?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/cvss_cli/metric_group.rb', line 51

def any_metric_set?
  @metrics.values.any? { |m| !m.value.nil? and m.value != 'x' and m.value != 'NIL' }
end

#calculate_score(base_score = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cvss_cli/metric_group.rb', line 18

def calculate_score(base_score = nil)
  case @name
  when "base"
    calculate_base_score
  when "temporal"
    calculate_temporal_score(base_score)
  when "environmental"
    calculate_environmental_score
  else
    raise NotImplementedError "invalid group name #{@name}"
  end
end

#get_cvss_stringObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cvss_cli/metric_group.rb', line 31

def get_cvss_string
  string = ""
  @metrics.values.each do |metric|
    if metric.value.nil? or metric.value == 'x'
      if print_nil_values
        string += "#{metric.key}:".upcase + "NIL"
        string += "/"
      end
    else
      string += "#{metric.key}:#{metric.value}".upcase
      string += "/"
    end
  end
  string
end


47
48
49
# File 'lib/cvss_cli/metric_group.rb', line 47

def print_size
  @metrics.values.map { |m| m.name.size }.max
end