Sha256: 2c0c8c6a2df3bc8e69aef55b7fc550638ae4d2ae56d8f346a112678781dac97f
Contents?: true
Size: 734 Bytes
Versions: 1
Compression:
Stored size: 734 Bytes
Contents
require 'loqate/util' module Loqate module Mappers # Transforms arrays of hashes into concrete instances of classes. # # @api private # class GenericMapper # Creates objects from an API response. The objects will be an instance of +object_class+. # # @param [Class] object_class Class of the final objects # @param [Array<Hash>] items Array of attributes to instantiate the final objects # # @return An array of objects of the given class # def map(items, object_class) items.map do |item| attributes = item.transform_keys { |attribute| Util.underscore(attribute) } object_class.new(attributes) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
loqate-0.2.0 | lib/loqate/mappers/generic_mapper.rb |