Class: PackAPI::Mapping::APIToModelAttributesTransformer

Inherits:
AbstractTransformer show all
Defined in:
lib/pack_api/mapping/api_to_model_attributes_transformer.rb

Overview

Specialized attribute transformer allowing API attributes be converted to the attribute names needed to creating/updating an ActiveRecord model.

Instance Attribute Summary

Attributes inherited from AbstractTransformer

#api_type, #data_source, #mappings, #model_type, #options

Instance Method Summary collapse

Methods inherited from AbstractTransformer

#initialize

Constructor Details

This class inherits a constructor from PackAPI::Mapping::AbstractTransformer

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pack_api/mapping/api_to_model_attributes_transformer.rb', line 8

def execute
  result = {}
  attribute_names = NormalizedAPIAttribute.new(api_attribute_names)
  data_source.each do |api_attribute, api_value|
    normalized_api_attribute = attribute_names.normalize(api_attribute)
    model_attribute = model_attribute(normalized_api_attribute)
    model_value = transform_value(normalized_api_attribute, api_value)
    result[model_attribute] = model_value
  end
  result
end