Class: CDMDEXER::RecordTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/cdmdexer/record_transformer.rb

Overview

“Record Transformation Error: ##message

Instance Attribute Summary collapse

Instance Method Summary collapse

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_klassObject (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_mappingsObject (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_transformerObject (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

#recordObject (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: message(error)).notify
end