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/ipt/tag_extraction.rb', line 4
def grep(pattern, ignore = /Auto-generated/)
output = []
formatter = Formatter.new
traverse do |file|
count, match, buffer = 0, false, []
open(file) do |f|
while line = f.gets
count += 1
if line =~ pattern && line !~ ignore
match = true
buffer << "#{count.to_s.rjust(8)}: #{line.strip}"
end
end
if match
output << "\n#{formatter.yellow(file)}"
output << buffer.join("\n")
output << "\n"
formatter.reset!
end
match = false
end
end
output.empty? ? "#{pattern} not found" : output.join("\n")
end
|