lib/request_log_analyzer/controller.rb in request-log-analyzer-1.0.4 vs lib/request_log_analyzer/controller.rb in request-log-analyzer-1.1.0
- old
+ new
@@ -27,21 +27,23 @@
attr_reader :options
# Builds a RequestLogAnalyzer::Controller given parsed command line arguments
# <tt>arguments<tt> A CommandLine::Arguments hash containing parsed commandline parameters.
# <rr>report_with</tt> Width of the report. Defaults to 80.
- def self.build(arguments, report_width = 80)
-
- options = { :report_width => arguments[:report_width].to_i, :output => STDOUT}
+ def self.build(arguments)
+ options = { }
options[:database] = arguments[:database] if arguments[:database]
options[:debug] = arguments[:debug]
- options[:colorize] = !arguments[:boring]
+ output_class = RequestLogAnalyzer::Output::const_get(arguments[:output])
if arguments[:file]
- options[:output] = File.new(arguments[:file], "w+")
- options[:colorize] = false
+ output_file = File.new(arguments[:file], "w+")
+ options[:output] = output_class.new(output_file, :width => 80, :color => false, :characters => :ascii)
+ else
+ options[:output] = output_class.new(STDOUT, :width => arguments[:report_width].to_i,
+ :color => !arguments[:boring], :characters => (arguments[:boring] ? :ascii : :utf))
end
# Create the controller with the correct file format
file_format = RequestLogAnalyzer::FileFormat.load(arguments[:format])
@@ -127,11 +129,11 @@
# <tt>message</tt> Current state (:started, :finished, :interupted or :progress).
# <tt>value</tt> File or current line.
def handle_progress(message, value = nil)
case message
when :started
- @progress_bar = ProgressBar.new(green(File.basename(value), options[:colorize]), File.size(value))
+ @progress_bar = CommandLine::ProgressBar.new(File.basename(value), File.size(value))
when :finished
@progress_bar.finish
@progress_bar = nil
when :interrupted
if @progress_bar
@@ -174,10 +176,12 @@
# 4. Call finalize on every aggregator
# 5. Call report on every aggregator
# 6. Finalize Source
def run!
+
+
@filters.each { |filter| filter.prepare }
@aggregators.each { |agg| agg.prepare }
begin
@source.requests do |request|
@@ -187,15 +191,18 @@
rescue Interrupt => e
handle_progress(:interrupted)
puts "Caught interrupt! Stopped parsing."
end
- puts "\n"
-
@aggregators.each { |agg| agg.finalize }
- @aggregators.each { |agg| agg.report(@output, options[:report_width], options[:colorize]) }
-
+
+ @output.header
+ @aggregators.each { |agg| agg.report(@output) }
+ @output.footer
+
@source.finalize
+
+
end
end
end