Class: ETL::Processor::EnsureFieldsPresenceProcessor
- Inherits:
-
RowProcessor
- Object
- Processor
- RowProcessor
- ETL::Processor::EnsureFieldsPresenceProcessor
- Defined in:
- lib/etl/processor/ensure_fields_presence_processor.rb
Overview
Ensure that each specified field is available
Instance Method Summary collapse
-
#initialize(control, configuration) ⇒ EnsureFieldsPresenceProcessor
constructor
Initialize the processor.
- #process(row) ⇒ Object
Methods inherited from RowProcessor
#ensure_columns_available_in_row!
Constructor Details
#initialize(control, configuration) ⇒ EnsureFieldsPresenceProcessor
Initialize the processor.
Configuration options:
-
:fields
: An array of keys whose presence should be verified in each row
10 11 12 13 14 |
# File 'lib/etl/processor/ensure_fields_presence_processor.rb', line 10 def initialize(control, configuration) super @fields = configuration[:fields] raise ControlError, ":fields must be specified" unless @fields end |
Instance Method Details
#process(row) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/etl/processor/ensure_fields_presence_processor.rb', line 16 def process(row) missing_fields = configuration[:fields].map(&:to_s) - row.keys.map(&:to_s) raise(ETL::ControlError, "Row missing required field(s) #{missing_fields.join(',')} in row. Available fields are : #{row.keys.join(',')}") unless missing_fields.empty? row end |