Class: Drupal::Todo_List
- Inherits:
-
Object
- Object
- Drupal::Todo_List
- Defined in:
- lib/drupal/todo_list.rb
Instance Method Summary collapse
-
#parse_dir(dir) ⇒ Object
Parse directory for todo items.
-
#parse_file(filepath) ⇒ Object
Parse file for todo items.
-
#run(arguments) ⇒ Object
Run todo list.
Instance Method Details
#parse_dir(dir) ⇒ Object
Parse directory for todo items.
34 35 36 37 38 |
# File 'lib/drupal/todo_list.rb', line 34 def parse_dir(dir) Dir["#{dir == '.' ? '.' : dir}/**/*"].each do |file| parse_file(file) if File.file?(file) end end |
#parse_file(filepath) ⇒ Object
Parse file for todo items.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/drupal/todo_list.rb', line 20 def parse_file(filepath) File.open(filepath) do |file| items = [] file.each_line do |line| matches = line.match /(?:#|\/\/|\/\*|@)[\s]*todo:?[\s]*(.+)$/i items << matches[1] unless matches.nil? || matches.length <= 0 @total += 1 unless matches.nil? || matches.length <= 0 end puts "\n" + filepath unless items.empty? || @total_only == true items.each{ |item| puts " - #{item}" } unless @total_only == true end end |
#run(arguments) ⇒ Object
Run todo list
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/drupal/todo_list.rb', line 6 def run(arguments) @total = 0 @arguments = arguments @total_only = true if @arguments[0] == 'total' @arguments.shift if @total_only == true parse_dir('.') if @arguments.empty? for argument in @arguments parse_file(argument) if File.file?(argument) parse_dir(argument) if File.directory?(argument) end puts "Total todo items: #{@total}" if @total_only == true end |