Class: IPT::TagExtraction

Inherits:
Object
  • Object
show all
Defined in:
lib/ipt/tag_extraction.rb

Instance Method Summary collapse

Instance Method Details

#grep(pattern, ignore = /Auto-generated/) ⇒ Object



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

#traverseObject



29
30
31
32
33
# File 'lib/ipt/tag_extraction.rb', line 29

def traverse
  Dir['**/*.{m,h,txt,md,markdown,rdoc,text}'].each do |fn|
    yield fn
  end
end