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
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 95

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

Instance Attribute Details

#assignmentObject (readonly)

Returns the value of attribute assignment.



48
49
50
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 48

def assignment
  @assignment
end

#branchObject (readonly)

Returns the value of attribute branch.



48
49
50
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 48

def branch
  @branch
end

#conditionObject (readonly)

Returns the value of attribute condition.



48
49
50
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 48

def condition
  @condition
end

Instance Method Details

#clearObject



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

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

#complexityObject



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

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

#condition_tableObject



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

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