class TodoFinder::Finder
Constants
- TODO_REGEX
Attributes
matches[RW]
Public Class Methods
new()
click to toggle source
# File lib/todo_finder.rb, line 10 def initialize @matches = Hash.new { |h,k| h[k]=[] } end
Public Instance Methods
find(dir='.')
click to toggle source
Find all TODOs in given dir and stuff them in a hash keyed by file
# File lib/todo_finder.rb, line 15 def find(dir='.') full_dir = File.expand_path File.join(Dir.pwd, dir, '**', '*') all_files = Dir[full_dir].reject { |file| File.directory? file } all_files.each do |file_name| File.open(file_name, :encoding => 'ISO-8859-1') do |file| file.each_with_index do |line, i| @matches[file_name] << [i + 1, line] if line =~ TODO_REGEX end end end return self end
output()
click to toggle source
Pretty output
# File lib/todo_finder.rb, line 31 def output @matches.each do |file, lines| file_name = '.' << file.sub(Dir.pwd, '') puts file_name.yellow lines.each do |i, line| line_num = i.to_s.green formatted_line = line.match(TODO_REGEX).captures.last puts " - [#{line_num}] " << formatted_line.strip end puts '' end end