Class: Guideline::AbcComplexityChecker::AbcParser

Inherits:
CodeAnalyzer::Checker
  • Object
show all
Includes:
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 Moduleable

#current_module_name, included, #modules

Constructor Details

#initialize(&callback) ⇒ AbcParser

Returns a new instance of AbcParser.



127
128
129
130
131
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 127

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

Instance Attribute Details

#assignmentObject (readonly)

Returns the value of attribute assignment.



80
81
82
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 80

def assignment
  @assignment
end

#branchObject (readonly)

Returns the value of attribute branch.



80
81
82
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 80

def branch
  @branch
end

#conditionObject (readonly)

Returns the value of attribute condition.



80
81
82
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 80

def condition
  @condition
end

Instance Method Details

#clearObject



133
134
135
136
137
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 133

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

#complexityObject



139
140
141
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 139

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

#condition_tableObject



143
144
145
146
147
148
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 143

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