Class: RequestLogAnalyzer::Output::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/request_log_analyzer/output.rb

Overview

Base Class used for generating output for reports. All output should inherit fromt this class.

Direct Known Subclasses

FixedWidth, HTML

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, options = {}) ⇒ Base

Initialize a report io iO Object (file, STDOUT, etc.) options Specific style options



46
47
48
49
50
# File 'lib/request_log_analyzer/output.rb', line 46

def initialize(io, options = {})
  @io      = io
  @options = options
  @style   = options[:style] || { cell_separator: true, table_border: false }
end

Instance Attribute Details

#ioObject

Returns the value of attribute io.



41
42
43
# File 'lib/request_log_analyzer/output.rb', line 41

def io
  @io
end

#optionsObject

Returns the value of attribute options.



41
42
43
# File 'lib/request_log_analyzer/output.rb', line 41

def options
  @options
end

#styleObject

Returns the value of attribute style.



41
42
43
# File 'lib/request_log_analyzer/output.rb', line 41

def style
  @style
end

Instance Method Details

Generate the footer of a report



69
70
# File 'lib/request_log_analyzer/output.rb', line 69

def footer
end

#headerObject

Generate a header for a report



65
66
# File 'lib/request_log_analyzer/output.rb', line 65

def header
end

#report_tracker(tracker) ⇒ Object



52
53
54
# File 'lib/request_log_analyzer/output.rb', line 52

def report_tracker(tracker)
  tracker.report(self)
end

#slice_results(array) ⇒ Object



72
73
74
75
# File 'lib/request_log_analyzer/output.rb', line 72

def slice_results(array)
  return array if options[:amount] == :all
  array.slice(0, options[:amount]) # otherwise
end

#table(*_columns, &_block) ⇒ Object

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(=> :left, {:align => :right }, => :right, => :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



98
99
# File 'lib/request_log_analyzer/output.rb', line 98

def table(*_columns, &_block)
end

#with_style(temp_style = {}) {|_self| ... } ⇒ Object

Apply a style block.. with style :)

Yields:

  • (_self)

Yield Parameters:



57
58
59
60
61
62
# File 'lib/request_log_analyzer/output.rb', line 57

def with_style(temp_style = {})
  old_style = @style
  @style = @style.merge(temp_style)
  yield(self) if block_given?
  @style = old_style
end