Class: Guideline::AbcComplexityChecker::AbcParser

Inherits:
CodeAnalyzer::Checker
  • Object
show all
Includes:
Parser::Moduleable
Defined in:
lib/guideline/checkers/abc_complexity_checker.rb

Constant Summary collapse

ASSIGNMENT_NODES =
[:assign, :opassign]
BRANCH_NODES =
[:call, :fcall, :vcall, :zsuper, :yield0, :brace_block, :do_block]
CONDITION_NODES =
[:else]
CONDITION_TOKENS =
[:==, :===, :"<>", :<=, :>=, :=~, :>, :<, :<=>]
ALL_NODES =
ASSIGNMENT_NODES + BRANCH_NODES + CONDITION_NODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser::Moduleable

#current_module_name, included, #modules

Constructor Details

#initialize(&callback) ⇒ AbcParser

Returns a new instance of AbcParser.



95
96
97
98
99
100
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 95

def initialize(*, &callback)
  clear
  @callback = callback
  @current_method = []
  super
end

Instance Attribute Details

#assignmentObject (readonly)

Returns the value of attribute assignment.



50
51
52
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 50

def assignment
  @assignment
end

#branchObject (readonly)

Returns the value of attribute branch.



50
51
52
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 50

def branch
  @branch
end

#conditionObject (readonly)

Returns the value of attribute condition.



50
51
52
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 50

def condition
  @condition
end

Instance Method Details

#clearObject



102
103
104
105
106
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 102

def clear
  @assignment = 0
  @branch     = 0
  @condition  = 0
end

#complexityObject



108
109
110
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 108

def complexity
  Math.sqrt(@assignment ** 2 + @branch ** 2 + @condition ** 2)
end

#condition_tableObject



112
113
114
115
116
117
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 112

def condition_table
  @condition_table ||= CONDITION_TOKENS.inject({}) do |hash, token|
    hash[token] = true
    hash
  end
end