Class: Codetip::App

Inherits:
Object
  • Object
show all
Defined in:
lib/codetip/app.rb

Direct Known Subclasses

Commander

Instance Method Summary collapse

Instance Method Details

#parse(path, restrict = '*', user = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/codetip/app.rb', line 3

def parse(path, restrict = '*', user = nil)
  result = {}
  Dir.glob(path + '/**/' + restrict) do |filename|
    if File.file?(filename)
      comments = {}
      lineNumber = 1
      File.readlines(filename).each do |line|
        if line.match(/\[(todo|warning|review)\](\s*[:-]+\s*(.+))$/i)
          type = $1.downcase
          message = $3
          next if (!user.nil? && !line.downcase.match(Regexp.new('@('+user.downcase + '|all)')))
          (comments[type] ||= []) << {
            :line => lineNumber,
            :message => message
          }
        end
        lineNumber += 1
      end
      if (comments.count > 0)
        result[filename] = comments
      end
    end
  end
  return result
end