Class: Analyst::Parser
- Inherits:
-
Object
- Object
- Analyst::Parser
- Extended by:
- Forwardable
- Defined in:
- lib/analyst/parser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(root) ⇒ Parser
constructor
A new instance of Parser.
- #inspect ⇒ Object
- #top_level_entities ⇒ Object
Constructor Details
#initialize(root) ⇒ Parser
Returns a new instance of Parser.
37 38 39 |
# File 'lib/analyst/parser.rb', line 37 def initialize(root) @root = root end |
Class Method Details
.for_files(path_to_files) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/analyst/parser.rb', line 12 def self.for_files(path_to_files) file_paths = if File.directory?(path_to_files) Dir.glob(File.join(path_to_files, "**", "*.rb")) else [path_to_files] end wrapped_asts = file_paths.map do |path| ast = ::Parser::CurrentRuby.parse(File.open(path, 'r').read) ::Parser::AST::Node.new(:analyst_file, [ast]) end root_node = ::Parser::AST::Node.new(:analyst_root, wrapped_asts) root = Entities::Root.new(root_node, file_paths) new(root) end |
.for_source(source) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/analyst/parser.rb', line 29 def self.for_source(source) ast = ::Parser::CurrentRuby.parse(source) wrapped_ast = ::Parser::AST::Node.new(:analyst_source, [ast]) root_node = ::Parser::AST::Node.new(:analyst_root, [wrapped_ast]) root = Entities::Root.new(root_node, [source]) new(root) end |
Instance Method Details
#inspect ⇒ Object
41 42 43 |
# File 'lib/analyst/parser.rb', line 41 def inspect "\#<#{self.class}:#{object_id}>" end |
#top_level_entities ⇒ Object
45 46 47 |
# File 'lib/analyst/parser.rb', line 45 def top_level_entities root.contents end |