Class: RequestLogAnalyzer::Output::Base
- Inherits:
-
Object
- Object
- RequestLogAnalyzer::Output::Base
- 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
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
-
#options ⇒ Object
Returns the value of attribute options.
-
#style ⇒ Object
Returns the value of attribute style.
Instance Method Summary collapse
-
#footer ⇒ Object
Generate the footer of a report.
-
#header ⇒ Object
Generate a header for a report.
-
#initialize(io, options = {}) ⇒ Base
constructor
Initialize a report
io
iO Object (file, STDOUT, etc.)options
Specific style options. - #slice_results(array) ⇒ Object
-
#table(*columns, &block) ⇒ Object
Generate a report table and push it into the output object.
-
#with_style(temp_style = {}) {|_self| ... } ⇒ Object
Apply a style block..
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, = {}) @io = io = @style = [:style] || { :cell_separator => true, :table_border => false } end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
49 50 51 |
# File 'lib/request_log_analyzer/output.rb', line 49 def io @io end |
#options ⇒ Object
Returns the value of attribute options.
49 50 51 |
# File 'lib/request_log_analyzer/output.rb', line 49 def end |
#style ⇒ Object
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
#footer ⇒ Object
Generate the footer of a report
73 74 |
# File 'lib/request_log_analyzer/output.rb', line 73 def end |
#header ⇒ Object
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 [:amount] == :all return array.slice(0, [: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 :)
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 |