Class: Reek::SmellDetectors::ControlParameterHelpers::Candidate

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/smell_detectors/control_parameter_helpers/candidate.rb

Overview

Collects information about a single control parameter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter, occurrences) ⇒ Candidate

Returns a new instance of Candidate.

Parameters:

  • parameter (Symbol)

    the parameter name

  • occurrences (Array<Reek::AST::Node>)

    the occurrences of the ControlParameter smell e.g. [s(:lvar, :bravo), s(:lvar, :bravo)]



15
16
17
18
# File 'lib/reek/smell_detectors/control_parameter_helpers/candidate.rb', line 15

def initialize(parameter, occurrences)
  @parameter = parameter
  @occurrences = occurrences
end

Instance Attribute Details

#occurrencesObject (readonly, private)

Returns the value of attribute occurrences.



34
35
36
# File 'lib/reek/smell_detectors/control_parameter_helpers/candidate.rb', line 34

def occurrences
  @occurrences
end

#parameterObject (readonly, private)

Returns the value of attribute parameter.



34
35
36
# File 'lib/reek/smell_detectors/control_parameter_helpers/candidate.rb', line 34

def parameter
  @parameter
end

Instance Method Details

#linesObject



24
25
26
# File 'lib/reek/smell_detectors/control_parameter_helpers/candidate.rb', line 24

def lines
  occurrences.map(&:line)
end

#nameObject



28
29
30
# File 'lib/reek/smell_detectors/control_parameter_helpers/candidate.rb', line 28

def name
  parameter.to_s
end

#smells?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/reek/smell_detectors/control_parameter_helpers/candidate.rb', line 20

def smells?
  occurrences.any?
end