Class: ImproveYourCode::SmellWarning

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/improve_your_code/smell_warning.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(smell_detector, context: '', lines:, message:, source:, parameters: {}) ⇒ SmellWarning

Returns a new instance of SmellWarning.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/improve_your_code/smell_warning.rb', line 13

def initialize(smell_detector, context: '', lines:, message:,
               source:, parameters: {})
  @smell_detector = smell_detector
  @source         = source
  @context        = context.to_s
  @lines          = lines
  @message        = message
  @parameters     = parameters

  freeze
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/improve_your_code/smell_warning.rb', line 10

def context
  @context
end

#linesObject (readonly)

Returns the value of attribute lines.



10
11
12
# File 'lib/improve_your_code/smell_warning.rb', line 10

def lines
  @lines
end

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/improve_your_code/smell_warning.rb', line 10

def message
  @message
end

#parametersObject (readonly)

Returns the value of attribute parameters.



10
11
12
# File 'lib/improve_your_code/smell_warning.rb', line 10

def parameters
  @parameters
end

#smell_detectorObject (readonly)

Returns the value of attribute smell_detector.



10
11
12
# File 'lib/improve_your_code/smell_warning.rb', line 10

def smell_detector
  @smell_detector
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/improve_your_code/smell_warning.rb', line 10

def source
  @source
end

Instance Method Details

#<=>(other) ⇒ Object



29
30
31
# File 'lib/improve_your_code/smell_warning.rb', line 29

def <=>(other)
  identifying_values <=> other.identifying_values
end

#base_messageObject



44
45
46
# File 'lib/improve_your_code/smell_warning.rb', line 44

def base_message
  "#{smell_type}: #{context} #{message}"
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/improve_your_code/smell_warning.rb', line 33

def eql?(other)
  (self <=> other).zero?
end

#hashObject



25
26
27
# File 'lib/improve_your_code/smell_warning.rb', line 25

def hash
  identifying_values.hash
end

#smell_classObject



48
49
50
# File 'lib/improve_your_code/smell_warning.rb', line 48

def smell_class
  smell_detector.class
end

#to_hashObject Also known as: yaml_hash



37
38
39
40
# File 'lib/improve_your_code/smell_warning.rb', line 37

def to_hash
  stringified_params = Hash[parameters.map { |key, val| [key.to_s, val] }]
  base_hash.merge(stringified_params)
end