Class: Loqate::Mappers::GenericMapper Private

Inherits:
Object
  • Object
show all
Defined in:
lib/loqate/mappers/generic_mapper.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Transforms arrays of hashes into concrete instances of classes.

Instance Method Summary collapse

Instance Method Details

#map(items, object_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates objects from an API response. The objects will be an instance of object_class.

Parameters:

  • object_class (Class)

    Class of the final objects

  • items (Array<Hash>)

    Array of attributes to instantiate the final objects

Returns:

  • An array of objects of the given class



17
18
19
# File 'lib/loqate/mappers/generic_mapper.rb', line 17

def map(items, object_class)
  items.map { |item| map_one(item, object_class) }
end

#map_one(item, object_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a single object from an API response. The object will be an instance of object_class.

Parameters:

  • object_class (Class)

    Class of the final object

  • item (Hash)

    Attributes to instantiate the final object

Returns:

  • An object of the given class



28
29
30
31
# File 'lib/loqate/mappers/generic_mapper.rb', line 28

def map_one(item, object_class)
  attributes = item.transform_keys { |attribute| Util.underscore(attribute) }
  object_class.new(attributes)
end