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



18
19
20
21
22
# File 'lib/request_log_analyzer/output.rb', line 18

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.



13
14
15
# File 'lib/request_log_analyzer/output.rb', line 13

def io
  @io
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/request_log_analyzer/output.rb', line 13

def options
  @options
end

#styleObject

Returns the value of attribute style.



13
14
15
# File 'lib/request_log_analyzer/output.rb', line 13

def style
  @style
end

Instance Method Details

Generate the footer of a report



37
38
# File 'lib/request_log_analyzer/output.rb', line 37

def footer
end

#headerObject

Generate a header for a report



33
34
# File 'lib/request_log_analyzer/output.rb', line 33

def header
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



61
62
# File 'lib/request_log_analyzer/output.rb', line 61

def table(*columns, &block)
end

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

Apply a style block.. with style :)

Yields:

  • (_self)

Yield Parameters:



25
26
27
28
29
30
# File 'lib/request_log_analyzer/output.rb', line 25

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