Sha256: 0a7ff7fcfc10ba081fc1d29397a8e68e730c099ce7309fe83535dd5ad522299c
Contents?: true
Size: 1.08 KB
Versions: 15
Compression:
Stored size: 1.08 KB
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 { |item| map_one(item, object_class) } end # Creates a single object from an API response. The object will be an instance of +object_class+. # # @param [Class] object_class Class of the final object # @param [Hash] item Attributes to instantiate the final object # # @return An object of the given class # def map_one(item, object_class) attributes = item.transform_keys { |attribute| Util.underscore(attribute) } object_class.new(attributes) end end end end
Version data entries
15 entries across 15 versions & 1 rubygems