module Bronze::Entities::Normalization::ClassMethods
Class methods to define when including Normalization
in a class.
Public Instance Methods
denormalize(attributes)
click to toggle source
Returns an entity instance from the given normalized representation.
@param attributes [Hash] A hash with String keys and normal values.
@return [Bronze::Entity] The entity.
# File lib/bronze/entities/normalization.rb, line 19 def denormalize(attributes) entity = new entity.send(:validate_attributes, attributes) each_attribute do |name, metadata| value = attributes[name] || attributes[name.to_s] value = metadata.transform.denormalize(value) if metadata.transform? next if value.nil? && metadata.primary_key? entity.set_attribute(name, value) end entity end