Class: Guideline::AbcComplexityChecker::AbcParser
- Inherits:
-
CodeAnalyzer::Checker
- Object
- CodeAnalyzer::Checker
- Guideline::AbcComplexityChecker::AbcParser
- 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
-
#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 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
#assignment ⇒ Object (readonly)
Returns the value of attribute assignment.
80 81 82 |
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 80 def assignment @assignment end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
80 81 82 |
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 80 def branch @branch end |
#condition ⇒ Object (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
#clear ⇒ Object
133 134 135 136 137 |
# File 'lib/guideline/checkers/abc_complexity_checker.rb', line 133 def clear @assignment = 0 @branch = 0 @condition = 0 end |
#complexity ⇒ Object
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_table ⇒ Object
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 |