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



54
55
56
57
58
# File 'lib/request_log_analyzer/output.rb', line 54

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.



49
50
51
# File 'lib/request_log_analyzer/output.rb', line 49

def io
  @io
end

#optionsObject

Returns the value of attribute options.



49
50
51
# File 'lib/request_log_analyzer/output.rb', line 49

def options
  @options
end

#styleObject

Returns the value of attribute style.



49
50
51
# File 'lib/request_log_analyzer/output.rb', line 49

def style
  @style
end

Instance Method Details

Generate the footer of a report



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

def footer
end

#headerObject

Generate a header for a report



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

def header
end

#slice_results(array) ⇒ Object



76
77
78
79
# File 'lib/request_log_analyzer/output.rb', line 76

def slice_results(array)
  return array if options[:amount] == :all
  return 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



102
103
# File 'lib/request_log_analyzer/output.rb', line 102

def table(*columns, &block)
end

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

Apply a style block.. with style :)

Yields:

  • (_self)

Yield Parameters:



61
62
63
64
65
66
# File 'lib/request_log_analyzer/output.rb', line 61

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