Class: Package::Audit::Risk

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/package/audit/models/risk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, explanation = nil) ⇒ Risk

Returns a new instance of Risk.



8
9
10
11
# File 'lib/package/audit/models/risk.rb', line 8

def initialize(type, explanation = nil)
  @type = type
  @explanation = explanation
end

Instance Attribute Details

#explanationObject (readonly)

Returns the value of attribute explanation.



6
7
8
# File 'lib/package/audit/models/risk.rb', line 6

def explanation
  @explanation
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/package/audit/models/risk.rb', line 6

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/package/audit/models/risk.rb', line 13

def <=>(other) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  if @type == other.type
    0
  elsif (@type == Enum::RiskType::HIGH && [Enum::RiskType::MEDIUM, Enum::RiskType::LOW,
                                           Enum::RiskType::NONE].include?(other.type)) ||
        (@type == Enum::RiskType::MEDIUM && [Enum::RiskType::LOW, Enum::RiskType::NONE].include?(other.type)) ||
        (@type == Enum::RiskType::LOW && [Enum::RiskType::NONE].include?(other.type))
    1
  else
    -1
  end
end