Class: Rubocop::Cop::Offence

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/offence.rb

Constant Summary collapse

SEVERITIES =
[:refactor, :convention, :warning, :error, :fatal]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(severity, line_number, message) ⇒ Offence

Returns a new instance of Offence.



10
11
12
13
14
# File 'lib/rubocop/cop/offence.rb', line 10

def initialize(severity, line_number, message)
  @severity = severity
  @line_number = line_number
  @message = message
end

Instance Attribute Details

#line_numberObject

Returns the value of attribute line_number.



6
7
8
# File 'lib/rubocop/cop/offence.rb', line 6

def line_number
  @line_number
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/rubocop/cop/offence.rb', line 6

def message
  @message
end

#severityObject

Returns the value of attribute severity.



6
7
8
# File 'lib/rubocop/cop/offence.rb', line 6

def severity
  @severity
end

Instance Method Details

#==(other) ⇒ Object



26
27
28
29
# File 'lib/rubocop/cop/offence.rb', line 26

def ==(other)
  severity == other.severity && line_number == other.line_number &&
    message == other.message
end

#encode_severityObject



22
23
24
# File 'lib/rubocop/cop/offence.rb', line 22

def encode_severity
  @severity.to_s[0].upcase
end

#explodeObject



31
32
33
# File 'lib/rubocop/cop/offence.rb', line 31

def explode
  [severity, line_number, message]
end

#to_sObject



16
17
18
19
20
# File 'lib/rubocop/cop/offence.rb', line 16

def to_s
  # we must be wary of messages containing % in them
  sprintf("#{encode_severity}:%3d: #{message.gsub(/%/, '%%')}",
          line_number)
end