Sha256: 8890d989c62bdaff21d3fce45941e71834153c71e33ab2cbc2b77f3b72a4398a

Contents?: true

Size: 903 Bytes

Versions: 20

Compression:

Stored size: 903 Bytes

Contents

module Simplabs

  module Excellent

    module Parsing

      module AbcMeasure #:nodoc:

        CONDITIONS = [:==, :<=, :>=, :<, :>]

        def process_lasgn(exp)
          @assignments ||= 0
          @assignments += 1
          super
        end

        def process_call(exp)
          handle_call(exp)
          super
        end

        def process_vcall(exp)
          handle_call(exp)
          super
        end

        def abc_score
          a = @assignments  ||= 0
          b = @branches     ||= 0
          c = @conditionals ||= 0
          Math.sqrt(a * a + b * b + c * c)
        end

        private

          def handle_call(exp)
            @branches     ||= 0
            @conditionals ||= 0
            if CONDITIONS.include?(exp[2])
              @conditionals += 1
            else
              @branches += 1
            end
          end

      end

    end

  end

end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.1 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.4.0 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.4.1 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.4.2 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.5.0 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/parsing/abc_measure.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-2.1.1 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-2.1.0 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-2.0.1 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-2.0.0 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-1.7.2 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-1.7.1 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-1.7.0 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-1.6.0 lib/simplabs/excellent/parsing/abc_measure.rb
excellent-1.5.4 lib/simplabs/excellent/parsing/abc_measure.rb