Class: CDMDEXER::RecordTransformer
- Inherits:
-
Object
- Object
- CDMDEXER::RecordTransformer
- Defined in:
- lib/cdmdexer/record_transformer.rb
Overview
“Record Transformation Error: ##message”
Instance Attribute Summary collapse
-
#error_klass ⇒ Object
readonly
Returns the value of attribute error_klass.
-
#field_mappings ⇒ Object
readonly
Returns the value of attribute field_mappings.
-
#field_transformer ⇒ Object
readonly
Returns the value of attribute field_transformer.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(record: {}, field_mappings: [], field_transformer: FieldTransformer, error_klass: TransformationErrorMessage) ⇒ RecordTransformer
constructor
A new instance of RecordTransformer.
- #transform! ⇒ Object
Constructor Details
#initialize(record: {}, field_mappings: [], field_transformer: FieldTransformer, error_klass: TransformationErrorMessage) ⇒ RecordTransformer
Returns a new instance of RecordTransformer.
5 6 7 8 9 10 11 12 13 |
# File 'lib/cdmdexer/record_transformer.rb', line 5 def initialize(record: {}, field_mappings: [], field_transformer: FieldTransformer, error_klass: TransformationErrorMessage) @record = record @field_mappings = field_mappings @field_transformer = field_transformer @error_klass = error_klass end |
Instance Attribute Details
#error_klass ⇒ Object (readonly)
Returns the value of attribute error_klass.
4 5 6 |
# File 'lib/cdmdexer/record_transformer.rb', line 4 def error_klass @error_klass end |
#field_mappings ⇒ Object (readonly)
Returns the value of attribute field_mappings.
4 5 6 |
# File 'lib/cdmdexer/record_transformer.rb', line 4 def field_mappings @field_mappings end |
#field_transformer ⇒ Object (readonly)
Returns the value of attribute field_transformer.
4 5 6 |
# File 'lib/cdmdexer/record_transformer.rb', line 4 def field_transformer @field_transformer end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
4 5 6 |
# File 'lib/cdmdexer/record_transformer.rb', line 4 def record @record end |
Instance Method Details
#transform! ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/cdmdexer/record_transformer.rb', line 15 def transform! field_mappings.inject({}) do |dest_record, field_mapping| dest_record.merge(transform_field(record, field_mapping)) end rescue StandardError => error error_klass.new(message: (error)).notify end |