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
ioiO Object (file, STDOUT, etc.)optionsSpecific style options. - #report_tracker(tracker) ⇒ Object
- #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
46 47 48 49 50 |
# File 'lib/request_log_analyzer/output.rb', line 46 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.
41 42 43 |
# File 'lib/request_log_analyzer/output.rb', line 41 def io @io end |
#options ⇒ Object
Returns the value of attribute options.
41 42 43 |
# File 'lib/request_log_analyzer/output.rb', line 41 def end |
#style ⇒ Object
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
#footer ⇒ Object
Generate the footer of a report
69 70 |
# File 'lib/request_log_analyzer/output.rb', line 69 def end |
#header ⇒ Object
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 [:amount] == :all 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.
-
:alignAlignment :left or :right -
:tresholdWidth in characters or :rest -
:type:ratio or nil -
:widthWidth 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 :)
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 |