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(asts) ⇒ Parser
constructor
A new instance of Parser.
- #inspect ⇒ Object
- #top_level_entities ⇒ Object
Constructor Details
#initialize(asts) ⇒ Parser
Returns a new instance of Parser.
52 53 54 55 |
# File 'lib/analyst/parser.rb', line 52 def initialize(asts) root_node = ::Parser::AST::Node.new(:analyst_root, asts) @root = Processor.process_node(root_node, nil) end |
Class Method Details
.for_files(*path_to_files) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/analyst/parser.rb', line 10 def self.for_files(*path_to_files) file_paths = path_to_files.flatten.map do |path| if File.directory?(path) Dir.glob(File.join(path, "**", "*.rb")) else path end end.flatten asts = file_paths.map do |path| File.open(path) do |file| parse_source(file.read, path) end end.compact new(asts) end |
.for_source(source) ⇒ Object
28 29 30 31 |
# File 'lib/analyst/parser.rb', line 28 def self.for_source(source) ast = parse_source(source) new([ast].compact) end |
Instance Method Details
#inspect ⇒ Object
57 58 59 |
# File 'lib/analyst/parser.rb', line 57 def inspect "\#<#{self.class}:#{object_id}>" end |
#top_level_entities ⇒ Object
61 62 63 |
# File 'lib/analyst/parser.rb', line 61 def top_level_entities root.contents end |