Parent

Roodi::Checks::AbcMetricMethodCheck

TODO: Add summary

TODO: Add detail

Constants

ASSIGNMENTS

ASSIGNMENTS = [:attrasgn, :attrset, :dasgn_curr, :iasgn, :lasgn, :masgn]

BRANCHES

BRANCHES = [:if, :else, :while, :until, :for, :rescue, :case, :when, :and, :or]

CONDITIONS

CONDITIONS = [:and, :or]

DEFAULT_SCORE
OPERATORS

*= /= %= += <<= >>= &= |= ^=

Public Class Methods

new(options = {}) click to toggle source
# File lib/roodi/checks/abc_metric_method_check.rb, line 19
def initialize(options = {})
  super()
  @score = options['score'] || DEFAULT_SCORE
end

Public Instance Methods

evaluate_start(node) click to toggle source
# File lib/roodi/checks/abc_metric_method_check.rb, line 28
def evaluate_start(node)
  method_name = node[1]
  a = count_assignments(node)
  b = count_branches(node)
  c = count_conditionals(node)
  score = Math.sqrt(a*a + b*b + c*c)
  add_error "Method name \"#{method_name}\" has an ABC metric score of <#{a},#{b},#{c}> = #{score}.  It should be #{@score} or less." unless score <= @score
end
interesting_nodes() click to toggle source
# File lib/roodi/checks/abc_metric_method_check.rb, line 24
def interesting_nodes
  [:defn]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.