Class: Drupal::Todo_List

Inherits:
Object
  • Object
show all
Defined in:
lib/drupal/todo_list.rb

Instance Method Summary collapse

Instance Method Details

#parse_dir(dir) ⇒ Object

Parse directory for todo items.



39
40
41
42
43
# File 'lib/drupal/todo_list.rb', line 39

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
32
33
34
35
36
# File 'lib/drupal/todo_list.rb', line 20

def parse_file(filepath)
  File.open(filepath) do |file|
    items = []
    linenumber = 0
    file.each_line do |line|
      linenumber += 1
      if summary = ToDo.extract_summary(line)
        context = ToDo.extract_context(linenumber, file)
        item = ToDo.new(linenumber, summary, context)
        @total += 1
        items << item.to_s
      end
    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