Class: Violation

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

Constant Summary collapse

WARNING =
'WARN'
FAILING_VIOLATION =
'FAIL'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, message:, logical_resource_ids: nil, violating_code: nil) ⇒ Violation

Returns a new instance of Violation.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/violation.rb', line 8

def initialize(type:,
               message:,
               logical_resource_ids: nil,
               violating_code: nil)
  @type = type
  @message = message
  @logical_resource_ids = logical_resource_ids
  @violating_code = violating_code

  fail if @type.nil?
  fail if @message.nil?
end

Instance Attribute Details

#logical_resource_idsObject (readonly)

Returns the value of attribute logical_resource_ids.



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

def logical_resource_ids
  @logical_resource_ids
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#violating_codeObject (readonly)

Returns the value of attribute violating_code.



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

def violating_code
  @violating_code
end

Instance Method Details

#==(other_violation) ⇒ Object



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

def ==(other_violation)
  other_violation.class == self.class && other_violation.to_h == to_h
end

#to_hObject



25
26
27
28
29
30
31
32
# File 'lib/violation.rb', line 25

def to_h
  {
    type: @type,
    message: @message,
    logical_resource_ids: @logical_resource_ids,
    violating_code: @violating_code
  }
end

#to_sObject



21
22
23
# File 'lib/violation.rb', line 21

def to_s
  puts "#{@type} #{@message} #{@logical_resource_ids} #{@violating_code}"
end