xmlblog (owner)

Fork Of

Forks

Revisions

gist: 123057 Download_button fork
public
Public Clone URL: git://gist.github.com/123057.git
Embed All Files: show embed
Ruby #
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Report
  
  BLANK = "".freeze
  
  class << self
    def publish(server, options = {})
      report = self.new
      report.process(options[:log], server)
    end
  end
  
  def initialize
    @output = ""
  end
  
  def process(input, server)
    @output = @header
    open_log(input, server) do |log|
      log.each_line do |line|
        line.scan(@regex).each do |matched|
          matched.each do |line_matched|
            @output << line_matched + "|"
          end
          @output << "#{server}\n"
        end
      end
      @output << "\n"
    end
  end
  
  private
 
  def open_log(log, server, &block)
    if File.exists?(log)
      open("#{LOGS_DIR}/#{server}/#{log}.#{PROCESS_DATE}.log", "r") do |f|
        block.call(f)
      end
    else
      STDERR.puts "Could not read #{log} on #{server}."
      BLANK
    end
  end
end