[ap4r-devel] [365] trunk/ap4r/Rakefile: Refactoring: extract methods

shino at rubyforge.org shino at rubyforge.org
Thu Jan 10 23:58:54 EST 2008


Revision: 365
Author:   shino
Date:     2008-01-10 23:58:54 -0500 (Thu, 10 Jan 2008)

Log Message:
-----------
Refactoring: extract methods

Modified Paths:
--------------
    trunk/ap4r/Rakefile

Modified: trunk/ap4r/Rakefile
===================================================================
--- trunk/ap4r/Rakefile	2008-01-11 04:21:38 UTC (rev 364)
+++ trunk/ap4r/Rakefile	2008-01-11 04:58:54 UTC (rev 365)
@@ -177,26 +177,29 @@
   end
 
   def print_todos(dir)
-    todo_pattern = /#\s*TODO\s*:?\s*(.*)\s(\d{4}\/\d{2}\/\d{2})\s*,?(?:by)?\s*(\S+)/i
-    exclude_file_patterns = [/~$/, /^#/]
-    Pathname.glob("#{dir}/**/*") do |file|
-      next unless file.file?
-      next if exclude_file_patterns.any? { |p| file.to_s =~ p }
+    FileList.new("#{dir}/**/*.*").each do |file|
+      next unless FileTest.file?(file)
+      next if (results = todos(file)).empty?
 
-      line_no = 0
-      first_time = true
-      file.each_line do |line|
-        line_no += 1
-        next unless todo_pattern.match(line)
+      puts file
+      results.each{ |r|
+        puts "L.#{"%4d" % r[:line]}: #{r[:msg]}  --  #{r[:date]} by #{r[:by]}"
+      }
+      puts
+    end
+  end
 
-        if first_time
-          puts file
-          first_time = false
-        end
-        puts "L.#{"%4d" % line_no}: #{$1}  --  #{$2.strip} by #{$3.strip}"
+  def todos(file)
+    pattern = /TODO\s*:?\s*(.*)\s+(\d{4}\/\d{2}\/\d{2})\s*,?(?:by)?\s*(\S+)/i
+
+    results = []
+    File.open(file, "r") do |f|
+      f.each_line do |line|
+        next unless pattern.match(line)
+        results << {:line => f.lineno, :by => $3, :date => $2, :msg => $1.strip}
       end
-      puts unless first_time
     end
+    results
   end
 
 end




More information about the ap4r-devel mailing list