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(id:, type:, message:, logical_resource_ids: nil, violating_code: nil) ⇒ Violation

Returns a new instance of Violation.



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

def initialize(id:,
               type:,
               message:,
               logical_resource_ids: nil,
               violating_code: nil)
  @id = id
  @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

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#logical_resource_idsObject (readonly)

Returns the value of attribute logical_resource_ids.



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

def logical_resource_ids
  @logical_resource_ids
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#violating_codeObject (readonly)

Returns the value of attribute violating_code.



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

def violating_code
  @violating_code
end

Instance Method Details

#==(other_violation) ⇒ Object



38
39
40
# File 'lib/violation.rb', line 38

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

#to_hObject



28
29
30
31
32
33
34
35
36
# File 'lib/violation.rb', line 28

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

#to_sObject



24
25
26
# File 'lib/violation.rb', line 24

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