Class: MOSAIK::Metrics::Complexity::Processor

Inherits:
AST::Processor
  • Object
show all
Defined in:
lib/mosaik/metrics/complexity/processor.rb

Overview

Abstract Syntax Tree parser for Ruby code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



14
15
16
17
18
19
# File 'lib/mosaik/metrics/complexity/processor.rb', line 14

def initialize
  super

  # Initialize complexities
  @complexities = {}
end

Instance Attribute Details

#complexitiesObject (readonly)

Returns the value of attribute complexities.



12
13
14
# File 'lib/mosaik/metrics/complexity/processor.rb', line 12

def complexities
  @complexities
end

Instance Method Details

#on_def(node) ⇒ Object

Instance methods



22
23
24
25
26
27
# File 'lib/mosaik/metrics/complexity/processor.rb', line 22

def on_def(node)
  method_name = node.children[0].to_s

  # Calculate and store complexity for the method
  complexities[method_name] = complexity_for(node)
end

#on_defs(node) ⇒ Object

Class methods



30
31
32
33
34
35
# File 'lib/mosaik/metrics/complexity/processor.rb', line 30

def on_defs(node)
  method_name = "self.#{node.children[1]}"

  # Calculate and store complexity for the method
  complexities[method_name] = complexity_for(node)
end