Todo_Marker/lib/todo_marker.rb
2024-06-14 23:00:56 -06:00

39 lines
845 B
Ruby

# frozen_string_literal: true
# lib/todo_marker.rb
require 'todo_marker/version'
require 'find'
module TodoMarker
TODO_REGEX = /# !!TODO!! "(.*?)"/
def self.generate_todo_md(directory)
todos = []
Find.find(directory) do |path|
next unless path.end_with?('.rb')
File.readlines(path).each_with_index do |line, index|
next unless line.match(TODO_REGEX)
todos << {
message: line.match(TODO_REGEX)[1],
file: path,
line: index + 1
}
end
end
create_todo_file(directory, todos)
end
def self.create_todo_file(directory, todos)
File.open(File.join(directory, 'TODO.md'), 'w') do |file|
file.puts "# TODO List\n\n"
todos.each do |todo|
file.puts "- #{todo[:message]} (#{todo[:file]}:#{todo[:line]})"
end
end
end
end