Class: MOSAIK::Metrics::Complexity::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaik/metrics/complexity/parser.rb

Overview

Parser for Ruby code

Instance Method Summary collapse

Instance Method Details

#parse(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mosaik/metrics/complexity/parser.rb', line 13

def parse(file)
  debug "Parsing file: #{file}"

  # Parse Abstract Syntax Tree
  source = RuboCop::AST::ProcessedSource
    .new(File.read(file), 3.3)

  # Process AST to extract complexity values from methods
  processor = Processor.new

  source.ast.each_node do |node|
    processor
      .process(node)
  end

  processor.complexities
end