Sha256: b81372987f58814f540fec75853d9f94632fd656921cd6c877a85630e95b8ba1

Contents?: true

Size: 768 Bytes

Versions: 10

Compression:

Stored size: 768 Bytes

Contents

require 'loqate/mappers/generic_mapper'
require 'loqate/error'
require 'loqate/util'

module Loqate
  module Mappers
    # Transforms erroneous responses into concrete error objects.
    #
    # @api private
    #
    class ErrorMapper
      # Creates errors from an API response
      #
      # @return [Array<Error>] An array of errors
      #
      def map(items)
        items.map { |item| map_one(item) }
      end

      # Creates an error from an API response
      #
      # @return [Error] A concrete instance of Error
      #
      def map_one(item)
        attributes = item.transform_keys { |attribute| Util.underscore(attribute) }
        attributes[:id] = attributes.delete(:error).to_i

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
loqate-0.10.2 lib/loqate/mappers/error_mapper.rb
loqate-0.10.1 lib/loqate/mappers/error_mapper.rb
loqate-0.10.0 lib/loqate/mappers/error_mapper.rb
loqate-0.9.0 lib/loqate/mappers/error_mapper.rb
loqate-0.8.0 lib/loqate/mappers/error_mapper.rb
loqate-0.7.0 lib/loqate/mappers/error_mapper.rb
loqate-0.6.0 lib/loqate/mappers/error_mapper.rb
loqate-0.5.0 lib/loqate/mappers/error_mapper.rb
loqate-0.4.0 lib/loqate/mappers/error_mapper.rb
loqate-0.3.0 lib/loqate/mappers/error_mapper.rb