This processor collects and formats reports from descendant entry processors.
Header string for the final compiled report.
Separator string to be inserted between individual reports.
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.
# 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
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.
# 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
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.
# File lib/sawmill/entry_processor/compile_report.rb, line 91 def to_postprocess_value(&block_) @postprocessor = block_ end