Module: Gemma::Utility
- Defined in:
- lib/gemma/utility.rb
Class Method Summary collapse
-
.print_usage_from_file_comment(file, comment_char = '#', io = $stdout) ⇒ Object
If the usage information for a script is documented in a comment block at the top of the file, this method prints it out.
-
.rgrep(tag, path, io = $stdout) ⇒ nil
A very simple recursive grep.
Class Method Details
.print_usage_from_file_comment(file, comment_char = '#', io = $stdout) ⇒ Object
If the usage information for a script is documented in a comment block at the top of the file, this method prints it out. If there is a shebang (#!) on the first line, it is not printed.
8 9 10 11 12 13 14 15 16 |
# File 'lib/gemma/utility.rb', line 8 def self.print_usage_from_file_comment file, comment_char='#', io=$stdout lines = File.readlines(file) lines.shift if lines.first =~ /^#!/ # ignore shebang for line in lines line.strip! break unless line =~ /^#{comment_char}(.*)/ io.puts $1 end end |
.rgrep(tag, path, io = $stdout) ⇒ nil
A very simple recursive grep.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gemma/utility.rb', line 29 def self.rgrep tag, path, io=$stdout Dir.chdir path do (Dir["**/*"] + Dir["**/.*"]).select {|f| File.file? f}.sort.each do |f| File.readlines(f).each_with_index do |line, i| io.puts "#{f}:#{i}: #{line}" if line =~ tag end end end nil end |