class RequestLogAnalyzer::Output::Base
Base
Class used for generating output for reports. All output should inherit fromt this class.
Attributes
Public Class Methods
Initialize a report io
iO Object
(file, STDOUT, etc.) options
Specific style options
# File lib/request_log_analyzer/output.rb 46 def initialize(io, options = {}) 47 @io = io 48 @options = options 49 @style = options[:style] || { cell_separator: true, table_border: false } 50 end
Public Instance Methods
Generate a header for a report
# File lib/request_log_analyzer/output.rb 65 def header 66 end
# File lib/request_log_analyzer/output.rb 52 def report_tracker(tracker) 53 tracker.report(self) 54 end
# File lib/request_log_analyzer/output.rb 72 def slice_results(array) 73 return array if options[:amount] == :all 74 array.slice(0, options[:amount]) # otherwise 75 end
Generate a report table and push it into the output object. Yeilds a rows array into which the rows can be pushed *colums<tt> Array of Column hashes (see Column options). <tt>&block
: A block yeilding the rows.
Column options¶ ↑
Columns is an array of hashes containing the column definitions.
-
:align
Alignment :left or :right -
:treshold
Width in characters or :rest -
:type
:ratio or nil -
:width
Width in characters or :rest
Example¶ ↑
The output object should support table definitions:
output.table({:align => :left}, {:align => :right }, {:align => :right}, {:type => :ratio, :width => :rest}) do |rows|
sorted_frequencies.each do |(cat, count)| rows << [cat, "#{count} hits", '%0.1f%%' % ((count.to_f / total_hits.to_f) * 100.0), (count.to_f / total_hits.to_f)] end
end
# File lib/request_log_analyzer/output.rb 98 def table(*_columns, &_block) 99 end
Apply a style block.. with style :)
# File lib/request_log_analyzer/output.rb 57 def with_style(temp_style = {}) 58 old_style = @style 59 @style = @style.merge(temp_style) 60 yield(self) if block_given? 61 @style = old_style 62 end
Protected Instance Methods
Check if a given table defination hash includes a header (title) columns
The columns hash
# File lib/request_log_analyzer/output.rb 105 def table_has_header?(columns) 106 columns.any? { |column| !column[:title].nil? } 107 end