Class: Sawmill::EntryProcessor::CompileReport
- Defined in:
- lib/sawmill/entry_processor/compile_report.rb
Overview
This processor collects and formats reports from descendant entry processors.
Instance Attribute Summary collapse
-
#footer ⇒ Object
Footer string for the final compiled report.
-
#header ⇒ Object
Header string for the final compiled report.
-
#separator ⇒ Object
Separator string to be inserted between individual reports.
Instance Method Summary collapse
-
#finish ⇒ Object
On finish, this processor calls finish on its descendants, converts their values into strings and compiles them into a report.
-
#initialize(*children_) ⇒ CompileReport
constructor
Create a report collection.
-
#to_postprocess_value(&block_) ⇒ Object
Provide a postprocessor block for individual report values.
Methods inherited from All
#attribute, #begin_record, #end_record, #message, #unknown_data
Methods inherited from Base
add_dsl_method, #attribute, #begin_record, #end_record, inherited, #message, #unknown_data
Constructor Details
#initialize(*children_) ⇒ CompileReport
Create a report collection.
Recognized options include:
:postprocessor-
Postprocessor proc for individual reports. See to_postprocess_value.
:separator-
Separator string to be inserted between individual reports. Default is a single newline.
:header-
Header string for the final compiled report. Default is the empty string.
:footer-
Footer string for the final compiled report. Default is the empty string.
66 67 68 69 70 71 72 73 |
# File 'lib/sawmill/entry_processor/compile_report.rb', line 66 def initialize(*children_) opts_ = children_.last.kind_of?(::Hash) ? children_.pop : {} @postprocessor = opts_[:postprocessor] @separator = opts_[:separator] || "\n" @header = opts_[:header] || '' @footer = opts_[:footer] || '' super(*children_) end |
Instance Attribute Details
#footer ⇒ Object
Footer string for the final compiled report.
83 84 85 |
# File 'lib/sawmill/entry_processor/compile_report.rb', line 83 def @footer end |
#header ⇒ Object
Header string for the final compiled report.
80 81 82 |
# File 'lib/sawmill/entry_processor/compile_report.rb', line 80 def header @header end |
#separator ⇒ Object
Separator string to be inserted between individual reports.
77 78 79 |
# File 'lib/sawmill/entry_processor/compile_report.rb', line 77 def separator @separator end |
Instance Method Details
#finish ⇒ Object
On finish, this processor calls finish on its descendants, converts their values into strings and compiles them into a report. It then returns that report as a string.
100 101 102 103 104 105 106 |
# File 'lib/sawmill/entry_processor/compile_report.rb', line 100 def finish values_ = super || [] values_ = [values_] unless values_.kind_of?(::Array) values_.map!{ |val_| @postprocessor.call(val_) } if @postprocessor values_.compact! "#{@header}#{values_.join(@separator)}#{@footer}" end |
#to_postprocess_value(&block_) ⇒ Object
Provide a postprocessor block for individual report values. This block should take a single parameter and return a string that should be included in the compiled report. It may also return nil to indicate that the data should not be included.
91 92 93 |
# File 'lib/sawmill/entry_processor/compile_report.rb', line 91 def to_postprocess_value(&block_) @postprocessor = block_ end |