Class: Laerad::FileAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/laerad/file_analyzer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ FileAnalyzer

Returns a new instance of FileAnalyzer.



11
12
13
14
15
16
17
# File 'lib/laerad/file_analyzer.rb', line 11

def initialize(path, options = {})
  @path = path
  @source = File.read(path)
  @scope_stack = [Scope.new]
  @result = Result.new(file: path)
  @options = options
end

Class Method Details

.analyze(path, options = {}) ⇒ Object



7
8
9
# File 'lib/laerad/file_analyzer.rb', line 7

def self.analyze(path, options = {})
  new(path, options).analyze
end

Instance Method Details

#analyzeObject



19
20
21
22
23
24
25
26
# File 'lib/laerad/file_analyzer.rb', line 19

def analyze
  ast = SyntaxTree.parse(@source)
  visit(ast)
  finalize_scope(@scope_stack.last)
  @result
rescue SyntaxTree::Parser::ParseError
  @result
end