class Sawmill::EntryProcessor::CompileReport

This processor collects and formats reports from descendant entry processors.

Attributes

header[RW]

Header string for the final compiled report.

separator[RW]

Separator string to be inserted between individual reports.

Public Class Methods

new(*children_) click to toggle source

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

Public Instance Methods

finish() click to toggle source

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
to_postprocess_value(&block_) click to toggle source

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