Class: Sawmill::RecordProcessor::CompileReport
- Defined in:
- lib/sawmill/record_processor/compile_report.rb
Overview
This processor collects and formats reports from descendant record 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
Methods inherited from Base
add_dsl_method, #extra_entry, inherited, #record
Constructor Details
#initialize(*children_) ⇒ CompileReport
Create a report collection.
Recognized options include:
:postprocessor-
Postprocessor proc for individual reports.
:separator-
Separator string for 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.
64 65 66 67 68 69 70 71 |
# File 'lib/sawmill/record_processor/compile_report.rb', line 64 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.
81 82 83 |
# File 'lib/sawmill/record_processor/compile_report.rb', line 81 def @footer end |
#header ⇒ Object
Header string for the final compiled report.
78 79 80 |
# File 'lib/sawmill/record_processor/compile_report.rb', line 78 def header @header end |
#separator ⇒ Object
Separator string to be inserted between individual reports.
75 76 77 |
# File 'lib/sawmill/record_processor/compile_report.rb', line 75 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.
98 99 100 101 102 103 104 |
# File 'lib/sawmill/record_processor/compile_report.rb', line 98 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.
89 90 91 |
# File 'lib/sawmill/record_processor/compile_report.rb', line 89 def to_postprocess_value(&block_) @postprocessor = block_ end |