Class: Loqate::Mappers::ErrorMapper Private

Inherits:
Object
  • Object
show all
Defined in:
lib/loqate/mappers/error_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 erroneous responses into concrete error objects.

Instance Method Summary collapse

Instance Method Details

#map(items) ⇒ Array<Error>

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 errors from an API response

Returns:

  • (Array<Error>)

    An array of errors



16
17
18
# File 'lib/loqate/mappers/error_mapper.rb', line 16

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

#map_one(item) ⇒ Error

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 an error from an API response

Returns:

  • (Error)

    A concrete instance of Error



24
25
26
27
28
29
# File 'lib/loqate/mappers/error_mapper.rb', line 24

def map_one(item)
  attributes = item.transform_keys { |attribute| Util.underscore(attribute) }
  attributes[:id] = attributes.delete(:error).to_i

  Loqate::Error.new(**attributes)
end