Class: Guideline::AbcComplexityChecker::AbcParser
- Inherits:
-
CodeAnalyzer::Checker
- Object
- CodeAnalyzer::Checker
- Guideline::AbcComplexityChecker::AbcParser
- 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
-
#assignment ⇒ Object
readonly
Returns the value of attribute assignment.
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
Instance Method Summary collapse
- #clear ⇒ Object
- #complexity ⇒ Object
- #condition_table ⇒ Object
-
#initialize(&callback) ⇒ AbcParser
constructor
A new instance of AbcParser.
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
#assignment ⇒ Object (readonly)
Returns the value of attribute assignment.
50 51 52 |
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 50 def assignment @assignment end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
50 51 52 |
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 50 def branch @branch end |
#condition ⇒ Object (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
#clear ⇒ Object
102 103 104 105 106 |
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 102 def clear @assignment = 0 @branch = 0 @condition = 0 end |
#complexity ⇒ Object
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_table ⇒ Object
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 |