Class: TodoAgent::Commands::Analyze

Inherits:
TodoAgent::Command show all
Defined in:
lib/todo_agent/commands/analyze.rb

Instance Method Summary collapse

Methods inherited from TodoAgent::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(path, options) ⇒ Analyze

Returns a new instance of Analyze.



12
13
14
15
# File 'lib/todo_agent/commands/analyze.rb', line 12

def initialize(path, options)
  @path = path
  @options = options
end

Instance Method Details

#execute(_input: $stdin, _output: $stdout) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/todo_agent/commands/analyze.rb', line 17

def execute(_input: $stdin, _output: $stdout)
  comments = []
  Rake::FileList["#{@path}/**/*"].exclude(paths_to_ignore).each do |filepath|
    parser = TodoAgent::FileIdentifier.based_on_file_extension(filepath)
    next unless parser

    parser_class = Object.const_get("TodoAgent::Parsers::#{parser}")
    result = parser_class.parse(filepath)
    comments += result
  end

  output(comments)
  nil
end