Class: Pelusa::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/pelusa/analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(lints, reporter, filename) ⇒ Analyzer

Public: Initializes an Analyzer.

ast - The abstract syntax tree to analyze. reporter - The class that will be used to create the report. filename - The name of the file that we're analyzing.


8
9
10
11
# File 'lib/pelusa/analyzer.rb', line 8

def initialize(lints, reporter, filename)
  @lints    = lints
  @reporter = reporter.new(filename)
end

Instance Method Details

#analyze(ast) ⇒ Object

Public: Makes a report out of several classes contained in the AST.

ast - The abstract syntax tree to analyze.

Returns a Report of all the classes.


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pelusa/analyzer.rb', line 18

def analyze(ast)
  reports = extract_classes(ast).map do |klass|
    class_analyzer = ClassAnalyzer.new(klass)
    class_name     = class_analyzer.class_name
    type           = class_analyzer.type
    analysis       = class_analyzer.analyze(@lints)

    Report.new(class_name, type, analysis)
  end
  @reporter.reports = reports
  @reporter
end