class TodoAgent::Commands::Analyze

Public Class Methods

new(path, options) click to toggle source
# File lib/todo_agent/commands/analyze.rb, line 12
def initialize(path, options)
  @path = path
  @options = options
end

Public Instance Methods

execute(_input: $stdin, _output: $stdout) click to toggle source
# 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

Private Instance Methods

output(comments) click to toggle source
# File lib/todo_agent/commands/analyze.rb, line 44
def output(comments)
  File.open(output_file, "w") do |f|
    comments.each do |comment|
      f.write "#{comment}\n"
    end
  end
end
output_file() click to toggle source
# File lib/todo_agent/commands/analyze.rb, line 52
def output_file
  @options["output_file"] || "todo_agent.log"
end
paths_to_ignore() click to toggle source
# File lib/todo_agent/commands/analyze.rb, line 34
def paths_to_ignore
  return [] if @options["ignore_paths"].nil?

  @options["ignore_paths"].map do |ignore_path|
    next ignore_path if ignore_path.start_with?(@path)

    "#{@path}/ignore_path"
  end
end