Module: BrowserShooter::LogExporter

Defined in:
lib/browser_shooter/log_exporter.rb

Class Method Summary collapse

Class Method Details

.export(logs, logs_path, format = "csv") ⇒ Object



3
4
5
6
7
8
9
# File 'lib/browser_shooter/log_exporter.rb', line 3

def self.export( logs, logs_path, format = "csv" )
  logs_path = File.expand_path( "#{logs_path}/log.#{format}" )
  BrowserShooter::Logger.log "Exporting '#{format}' logs to #{logs_path}"
  FileUtils.mkdir_p( File.dirname( logs_path ) )

  send(:"export_to_#{format}", logs, logs_path )
end

.export_to_csv(logs, path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/browser_shooter/log_exporter.rb', line 11

def self.export_to_csv( logs, path )
  File.open( path, "w" ) do |f|
    f.puts "time | success | command | message"

    logs.each do |result|
      line = "#{result[:time]} | #{result[:success]} | #{result[:command]} | #{result[:message]}".gsub( "\n", " - " )
      f.puts line
    end
  end
end